diff --git a/composer.json b/composer.json index d430bc9..8b4d6ff 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "php": ">=5.3", "react/event-loop": "~0.4.0|~0.3.0", "clue/buzz-react": "~0.2.0", - "ext-simplexml": "*" + "ext-simplexml": "*", + "neitanod/forceutf8": "~1.4" }, "require-dev": { "clue/block-react": "~0.1.0" diff --git a/src/Io/Loader.php b/src/Io/Loader.php index f8e8a78..c40ae59 100644 --- a/src/Io/Loader.php +++ b/src/Io/Loader.php @@ -26,6 +26,9 @@ public function loadXmlFile($path) public function loadXmlString($html) { + // log output often uses garbled ISO-8859-1 and UTF-8 encodings + $html = \ForceUTF8\Encoding::toUTF8($html); + // fix invalid markup of outdated ViewVC versions // - help link in footer not terminated // - selected branch/tag in CVS "sticky tag" dropdown has not attribute value diff --git a/tests/Io/LoaderTest.php b/tests/Io/LoaderTest.php index 152297c..f1709c2 100644 --- a/tests/Io/LoaderTest.php +++ b/tests/Io/LoaderTest.php @@ -39,6 +39,15 @@ public function testHtmlEntities() $this->assertEquals('ä… ©', (string)$xml); } + public function testMixedEncodings() + { + // mixed UTF-8 and ISO-8859-1 + $str = "

ä and \xFC

"; + $xml = $this->loader->loadXmlString($str); + + $this->assertEquals('ä and ü', (string)$xml); + } + public function testLoadInvalidMarkupInputNotClosed() { $str = '';