Skip to content

DOM: Svg attributes and tag names are being lowercased #18090

Closed

Description

@xPaw

Description

All attributes are being lowercased, but for svg elements they should have correct casing (e.g. viewbox should be viewBox).

\Dom\HTMLDocument::createFromString( '<html><body><svg VIEWBOX="1 2 3 4"></svg></html>' )->saveHTML()
// <html><head></head><body><svg viewbox="1 2 3 4"></svg></body></html>


\Dom\HTMLDocument::createFromString( '<html><body><svg VIEWBOX="1 2 3 4"><feSpotLight x="10" y="10" z="50" pointsAtX="100" pointsAtY="100" limitingConeAngle="
10" /></svg></html>' )->saveHTML();
// <html><head></head><body><svg viewbox="1 2 3 4"><fespotlight x="10" y="10" z="50" pointsatx="100" pointsaty="100" limitingconeangle="10"></fespotlight></svg></body></html>


\Dom\HTMLDocument::createFromString( '<html><body><svg VIEWBOX="1 2 3 4"></svg></html>' )->querySelector('svg')->attributes[0]->name;
// viewbox

Browser repro:

dom = (new DOMParser).parseFromString('<html><body><svg VIEWBOX="1 2 3 4"></svg></html>','text/html') 
dom.documentElement.outerHTML
// <html><head></head><body><svg viewBox="1 2 3 4"></svg></body></html>


dom = (new DOMParser).parseFromString('<html><head></head><body><svg viewbox="1 2 3 4"><fespotlight x="10" y="10" z="50" pointsatx="100" pointsaty="100" limitingconeangle="10"></fespotlight></svg></body></html>','text/html') 
dom.documentElement.outerHTML
// <html><head></head><body><svg viewBox="1 2 3 4"><feSpotLight x="10" y="10" z="50" pointsAtX="100" pointsAtY="100" limitingConeAngle="10"></feSpotLight></svg></body></html>

Ref: https://html.spec.whatwg.org/multipage/parsing.html#creating-and-inserting-nodes (there is a table of attributes if you scroll a bit, there's another table for tag names as well).

Lexbor does have this attribute mapping in the code, so maybe php is just skipping it somehow: https://github.com/lexbor/lexbor/blob/9283215c15c3c7a5106a1a1e3ff16ff89900a1a5/source/lexbor/html/tree_res.h#L31

PHP Version

8.4.5

Operating System

No response

Activity

  1. added a commit that references this issue on Mar 16, 2025
    0154bb5
  2. added 2 commits that reference this issue on Mar 17, 2025
    d7e2f28
    647baec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions