Skip to content

Commit 2ed2e7f

Browse files
committed
Support broken markup generated by older ViewVC versions
1 parent a0bc962 commit 2ed2e7f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Io/Loader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,13 @@ public function loadXmlFile($path)
2626

2727
public function loadXmlString($html)
2828
{
29-
// fix invalid markup of help link in footer of outdated ViewVC versions
29+
// fix invalid markup of outdated ViewVC versions
30+
// - help link in footer not terminated
31+
// - selected branch/tag in CVS "sticky tag" dropdown has not attribute value
32+
// - clear button for selected branch/tag has no trailing slash
3033
$html = str_replace('Help</strong></td>', 'Help</a></strong></td>', $html);
34+
$html = str_replace('selected>', 'selected="selected">', $html);
35+
$html = preg_replace('#<input([^\/]+)>#', '<input$1 />', $html);
3136

3237
// replace named HTML entities with their UTF-8 value
3338
$html = str_replace(array_values($this->entities), array_keys($this->entities), $html);

tests/Io/LoaderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,20 @@ public function testHtmlEntities()
3838
// c3 a4 e2 80 a6 c2 a0 c2 a9
3939
$this->assertEquals('ä… ©', (string)$xml);
4040
}
41+
42+
public function testLoadInvalidMarkupInputNotClosed()
43+
{
44+
$str = '<input type="hidden">';
45+
$xml = $this->loader->loadXmlString($str);
46+
47+
$this->assertEquals('hidden', (string)$xml['type']);
48+
}
49+
50+
public function testLoadInvalidMarkupSelectedAttributeNoValue()
51+
{
52+
$str = '<option selected>this</option>';
53+
$xml = $this->loader->loadXmlString($str);
54+
55+
$this->assertEquals('selected', (string)$xml['selected']);
56+
}
4157
}

0 commit comments

Comments
 (0)