Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transcode mixed encodings to UTF-8 #12

Merged
merged 1 commit into from
Apr 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/Io/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/Io/LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ public function testHtmlEntities()
$this->assertEquals('ä… ©', (string)$xml);
}

public function testMixedEncodings()
{
// mixed UTF-8 and ISO-8859-1
$str = "<p>ä and \xFC</p>";
$xml = $this->loader->loadXmlString($str);

$this->assertEquals('ä and ü', (string)$xml);
}

public function testLoadInvalidMarkupInputNotClosed()
{
$str = '<input type="hidden">';
Expand Down