fguillot/miniflux — pull request #34 by Necku (2013-05-22 13:41:35+00:00)
Title: Fix for old libxml bug

Forget the clean solution, there is none to this mess.

The bug as I understand it. This version of libxml double encodes UTF-8 characters but at the same time decodes entities properly. For example " " will become "c2a0", which is correct UTF-8 for unbreakable space. But at the same time "c2a0" in the input will be re-encoded in UTF-8 and output "c382c2a0". As a result the output contain both double encoded UTF-8 and proper UTF-8. When using utf8_decode on it, double encoded characters are fixed but correct ones are broken.

The fix I propose does the following:
1) replace "control" entities (& < >) by a unique token.
2) decode all other entities so that the input contains only Unicode.
3) put the "control" entities back.
4) normal processing.
5) apply utf8_decode; since all input is Unicode, no invalid characters are generated.

Note: the current code will work, but some characters will be broke on display (question marks). This fixes the issue completely but is quite dirty, your call!