You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/Webfactory/Dom/Test/PolyglotHTML5ParsingHelperTest.php
+35Lines changed: 35 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -44,4 +44,39 @@ public function testHtmlEntitiesSupportedAsConvenience()
44
44
45
45
$this->assertEquals('<p>ä x ö x ü " < > \' <x foo="" < > \'"></x></p>', $d);
46
46
}
47
+
48
+
publicfunctiontestSvgNamespaceIsNotReconciled()
49
+
{
50
+
/*
51
+
* libxml2 will attempt (under which circumstances?) to reconciliate namespace declarations, that is, find
52
+
* namespaces used by several nodes and move these declarations up the DOM tree.
53
+
*
54
+
* This also affects the default namespace as commonly used by <svg> inlined in HTML5 documents. As you cannot
55
+
* move the default namespace away from an element, libxml turns it into a regular "named" namespace and
56
+
* chooses a namespace prefix like "default" (sic), possibly followed by a number, for it. This happens
57
+
* in xmlNewReconciliedNs, see https://github.com/GNOME/libxml2/blob/35e83488505d501864826125cfe6a7950d6cba78/tree.c#L6230.
58
+
*
59
+
* The result is that markup like <svg xmlns="http://www.w3.org/2000/svg"><path ...></path></svg> will be turned
60
+
* into <default:svg><default:path>...</default:path></default:svg>, with xmlns:default="http://www.w3.org/2000/svg"
61
+
* somewhere up the tree.
62
+
*
63
+
* This is reported (not for the SVG namespace, but the general case) at https://bugs.php.net/bug.php?id=55294
64
+
* and https://bugs.php.net/bug.php?id=47530, with the conclusion that it would need to be fixed in libxml2.
65
+
*
66
+
* libxml2, on the other hand, will argue that the result is perfectly fine when applying XML semantics. The
67
+
* problem is that browsers may or may not make this distinction. According to https://stackoverflow.com/questions/18467982/are-svg-parameters-such-as-xmlns-and-version-needed,
68
+
* it might depend on wheter the page is served as application/xhtml+xml or text/html. In the latter case,
69
+
* XML namespace semantics do not apply.
70
+
*
71
+
* For <svg> in HTML5, a possible workaround is to completely remove the XML NS declaration: This is
72
+
* possible as <svg> is included in HTML5 as a "foreign element" (https://www.w3.org/TR/html5/syntax.html#foreign-elements).
73
+
* That is, the elements from the SVG namespace are also valid in HTML5.
74
+
*
75
+
* Instead of completely removing the xmlns, our current workaround is to move the namespace declaration
76
+
* "out of the way" when parsing the XML and fixing it up again later when dumping the XML.
0 commit comments