Skip to content

Commit 0154bb5

Browse files
committed
Fix phpGH-18090: DOM: Svg attributes and tag names are being lowercased
1 parent 3bb3db5 commit 0154bb5

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

ext/dom/html5_parser.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ static lexbor_libxml2_bridge_status lexbor_libxml2_bridge_convert(
138138
* If a prefix:name format is used, then the local name will be "prefix:name" and the prefix will be empty.
139139
* There is however still somewhat of a concept of namespaces. There are three: HTML (the default), SVG, and MATHML. */
140140
lxb_dom_element_t *element = lxb_dom_interface_element(node);
141-
const lxb_char_t *name = lxb_dom_element_local_name(element, NULL);
141+
const lxb_char_t *name = lxb_dom_element_qualified_name(element, NULL);
142+
ZEND_ASSERT(!element->node.prefix);
143+
142144
xmlNodePtr lxml_element = xmlNewDocNode(lxml_doc, NULL, name, NULL);
143145
if (UNEXPECTED(lxml_element == NULL)) {
144146
retval = LEXBOR_LIBXML2_BRIDGE_STATUS_OOM;
@@ -203,7 +205,13 @@ static lexbor_libxml2_bridge_status lexbor_libxml2_bridge_convert(
203205
for (lxb_dom_attr_t *attr = element->first_attr; attr != NULL; attr = attr->next) {
204206
/* Same namespace remark as for elements */
205207
size_t local_name_length, value_length;
206-
const lxb_char_t *local_name = lxb_dom_attr_local_name(attr, &local_name_length);
208+
const lxb_char_t *local_name = lxb_dom_attr_qualified_name(attr, &local_name_length);
209+
if (attr->node.prefix) {
210+
const char *pos = strchr((const char *) local_name, ':');
211+
if (EXPECTED(pos)) {
212+
local_name = (const lxb_char_t *) pos + 1;
213+
}
214+
}
207215
const lxb_char_t *value = lxb_dom_attr_value(attr, &value_length);
208216

209217
if (UNEXPECTED(local_name_length >= INT_MAX || value_length >= INT_MAX)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-18090 (Svg attributes and tag names are being lowercased)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
echo \Dom\HTMLDocument::createFromString('<html><body><svg VIEWBOX="1 2 3 4"></svg></html>', LIBXML_NOERROR)->saveHTML(), "\n";
8+
9+
echo \Dom\HTMLDocument::createFromString('<html><body CLASS="no"><svg VIEWBOX="1 2 3 4"><feSpotLight x="10" y="10" z="50" pointsAtX="100" pointsAtY="100" limitingConeAngle="
10+
10" /></svg></html>', LIBXML_NOERROR)->saveHTML(), "\n";
11+
12+
echo \Dom\HTMLDocument::createFromString('<html><body><svg VIEWBOX="1 2 3 4"></svg></html>', LIBXML_NOERROR)->querySelector('svg')->attributes[0]->name, "\n";
13+
?>
14+
--EXPECT--
15+
<html><head></head><body><svg viewBox="1 2 3 4"></svg></body></html>
16+
<html><head></head><body class="no"><svg viewBox="1 2 3 4"><feSpotLight x="10" y="10" z="50" pointsAtX="100" pointsAtY="100" limitingConeAngle="
17+
10"></feSpotLight></svg></body></html>
18+
viewBox

ext/dom/tests/modern/html/parser/predefined_namespaces.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ echo $dom->saveXml();
4747
svg http://www.w3.org/2000/svg
4848
Attribute: width (NONE)
4949
Attribute: height (NONE)
50-
Attribute: viewbox (NONE)
50+
Attribute: viewBox (NONE)
5151
rect http://www.w3.org/2000/svg
5252
Attribute: id (NONE)
5353
Attribute: x (NONE)
@@ -65,7 +65,7 @@ svg http://www.w3.org/1998/Math/MathML
6565
<title>Test</title>
6666
</head>
6767
<body>
68-
<svg width="100" height="100" viewbox="0 0 4 2">
68+
<svg width="100" height="100" viewBox="0 0 4 2">
6969
<rect id="rectangle" x="10" y="20" width="90" height="60">
7070
</rect>
7171
</svg>
@@ -85,7 +85,7 @@ svg http://www.w3.org/1998/Math/MathML
8585
<title>Test</title>
8686
</head>
8787
<body>
88-
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewbox="0 0 4 2">
88+
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 4 2">
8989
<rect id="rectangle" x="10" y="20" width="90" height="60">
9090
</rect>
9191
</svg>

0 commit comments

Comments
 (0)