Skip to content

Commit cf14a79

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

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

ext/dom/html5_parser.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,13 @@ static lexbor_libxml2_bridge_status lexbor_libxml2_bridge_convert(
203203
for (lxb_dom_attr_t *attr = element->first_attr; attr != NULL; attr = attr->next) {
204204
/* Same namespace remark as for elements */
205205
size_t local_name_length, value_length;
206-
const lxb_char_t *local_name = lxb_dom_attr_local_name(attr, &local_name_length);
206+
const lxb_char_t *local_name = lxb_dom_attr_qualified_name(attr, &local_name_length);
207+
if (attr->node.prefix) {
208+
const char *pos = strchr((const char *) local_name, ':');
209+
if (EXPECTED(pos)) {
210+
local_name = (const lxb_char_t *) pos + 1;
211+
}
212+
}
207213
const lxb_char_t *value = lxb_dom_attr_value(attr, &value_length);
208214

209215
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)