Skip to content

Fix GH-18090: DOM: Svg attributes and tag names are being lowercased #18091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ext/dom/html5_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ static lexbor_libxml2_bridge_status lexbor_libxml2_bridge_convert(
* If a prefix:name format is used, then the local name will be "prefix:name" and the prefix will be empty.
* There is however still somewhat of a concept of namespaces. There are three: HTML (the default), SVG, and MATHML. */
lxb_dom_element_t *element = lxb_dom_interface_element(node);
const lxb_char_t *name = lxb_dom_element_local_name(element, NULL);
const lxb_char_t *name = lxb_dom_element_qualified_name(element, NULL);
ZEND_ASSERT(!element->node.prefix);

xmlNodePtr lxml_element = xmlNewDocNode(lxml_doc, NULL, name, NULL);
if (UNEXPECTED(lxml_element == NULL)) {
retval = LEXBOR_LIBXML2_BRIDGE_STATUS_OOM;
Expand Down Expand Up @@ -203,7 +205,13 @@ static lexbor_libxml2_bridge_status lexbor_libxml2_bridge_convert(
for (lxb_dom_attr_t *attr = element->first_attr; attr != NULL; attr = attr->next) {
/* Same namespace remark as for elements */
size_t local_name_length, value_length;
const lxb_char_t *local_name = lxb_dom_attr_local_name(attr, &local_name_length);
const lxb_char_t *local_name = lxb_dom_attr_qualified_name(attr, &local_name_length);
if (attr->node.prefix) {
const char *pos = strchr((const char *) local_name, ':');
if (EXPECTED(pos)) {
local_name = (const lxb_char_t *) pos + 1;
}
}
const lxb_char_t *value = lxb_dom_attr_value(attr, &value_length);

if (UNEXPECTED(local_name_length >= INT_MAX || value_length >= INT_MAX)) {
Expand Down
18 changes: 18 additions & 0 deletions ext/dom/tests/modern/html/parser/gh18090.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
GH-18090 (Svg attributes and tag names are being lowercased)
--EXTENSIONS--
dom
--FILE--
<?php
echo \Dom\HTMLDocument::createFromString('<html><body><svg VIEWBOX="1 2 3 4"></svg></html>', LIBXML_NOERROR)->saveHTML(), "\n";

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" /></svg></html>', LIBXML_NOERROR)->saveHTML(), "\n";

echo \Dom\HTMLDocument::createFromString('<html><body><svg VIEWBOX="1 2 3 4"></svg></html>', LIBXML_NOERROR)->querySelector('svg')->attributes[0]->name, "\n";
?>
--EXPECT--
<html><head></head><body><svg viewBox="1 2 3 4"></svg></body></html>
<html><head></head><body class="no"><svg viewBox="1 2 3 4"><feSpotLight x="10" y="10" z="50" pointsAtX="100" pointsAtY="100" limitingConeAngle="
10"></feSpotLight></svg></body></html>
viewBox
6 changes: 3 additions & 3 deletions ext/dom/tests/modern/html/parser/predefined_namespaces.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ echo $dom->saveXml();
svg http://www.w3.org/2000/svg
Attribute: width (NONE)
Attribute: height (NONE)
Attribute: viewbox (NONE)
Attribute: viewBox (NONE)
rect http://www.w3.org/2000/svg
Attribute: id (NONE)
Attribute: x (NONE)
Expand All @@ -65,7 +65,7 @@ svg http://www.w3.org/1998/Math/MathML
<title>Test</title>
</head>
<body>
<svg width="100" height="100" viewbox="0 0 4 2">
<svg width="100" height="100" viewBox="0 0 4 2">
<rect id="rectangle" x="10" y="20" width="90" height="60">
</rect>
</svg>
Expand All @@ -85,7 +85,7 @@ svg http://www.w3.org/1998/Math/MathML
<title>Test</title>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewbox="0 0 4 2">
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 4 2">
<rect id="rectangle" x="10" y="20" width="90" height="60">
</rect>
</svg>
Expand Down
Loading