Skip to content

Commit d7f300a

Browse files
committed
Improve parsing broken markup
1 parent b17c09e commit d7f300a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Io/Loader.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ public function loadXmlString($html)
2929
// fix invalid markup of outdated ViewVC versions
3030
// - help link in footer not terminated
3131
// - selected branch/tag in CVS "sticky tag" dropdown has not attribute value
32-
// - clear button for selected branch/tag has no trailing slash
32+
// - self closing elements with no trailing slash
33+
// - excessive form close tags
3334
$html = str_replace('Help</strong></td>', 'Help</a></strong></td>', $html);
3435
$html = str_replace('selected>', 'selected="selected">', $html);
35-
$html = preg_replace('#<input([^\/]+)>#', '<input$1 />', $html);
36+
$html = preg_replace('#<((?:input|br|hr|img)[^\/\>]*)>#', '<$1 />', $html);
37+
$html = preg_replace('#(</table>\s*)</form>\s*(</div>)#', '$1$2', $html);
3638

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

tests/Io/LoaderTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public function testLoadInvalidMarkupInputNotClosed()
4747
$this->assertEquals('hidden', (string)$xml['type']);
4848
}
4949

50+
public function testPrepareInvalidMarkupBrNotClosed()
51+
{
52+
$html = '<br>';
53+
$xml = $this->loader->loadXmlString($html);
54+
}
55+
5056
public function testLoadInvalidMarkupSelectedAttributeNoValue()
5157
{
5258
$str = '<option selected>this</option>';

0 commit comments

Comments
 (0)