b-fuze / deno-dom

Browser DOM & HTML parser in Deno
https://jsr.io/@b-fuze/deno-dom
MIT License
423 stars 47 forks source link

`getNamedItem` discrepancy between browser and deno_dom 0.1.36 #133

Open cscheid opened 1 year ago

cscheid commented 1 year ago

Note the discrepancy with case sensitivity of some attributes (specifically, viewbox vs viewBox).

On Google Chrome:

> (new DOMParser()).parseFromString('<svg width="371pt" height="247pt" viewbox="0.00 0.00 370.99 246.71"></svg>', 'text/html').querySelector("svg").attributes.getNamedItem("viewBox")
viewBox=​"0.00 0.00 370.99 246.71"

> (new DOMParser()).parseFromString('<svg width="371pt" height="247pt" viewbox="0.00 0.00 370.99 246.71"></svg>', 'text/html').querySelector("svg").attributes.getNamedItem("viewbox")
null

On deno_dom 0.1.36:

> import {
  DOMParser,
  Element,
} from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
Download ⠧ https://deno.land/x/deno_dom/deno-dom-wasm.ts
Warning Implicitly using latest version (v0.1.36-alpha) for https://deno.land/x/deno_dom/deno-dom-wasm.ts

> (new DOMParser()).parseFromString('<svg width="371pt" height="247pt" viewbox="0.00 0.00 370.99 246.71"></svg>', 'text/html').querySelector("svg").attributes.getNamedItem("viewBox")
null

> (new DOMParser()).parseFromString('<svg width="371pt" height="247pt" viewbox="0.00 0.00 370.99 246.71"></svg>', 'text/html').querySelector("svg").attributes.getNamedItem("viewbox")
EventTarget {
  childNodes: [],
  parentNode: null,
  parentElement: null,
  _ancestors: Set {},
  nodeName: "viewbox",
  nodeType: 2,
  [Symbol()]: {
    assignedSlot: false,
    hasActivationBehavior: false,
    host: null,
    listeners: {},
    mode: ""
  },
  [Symbol("[[webidl.brand]]")]: Symbol("[[webidl.brand]]")
}
b-fuze commented 1 year ago

That is caused by Deno DOM not yet being able to produce XML nodes (which includes embedded XML documents as in your case) properly...

I just checked the parser and html5ever does knows that an SVG tag should be parsed as an embedded XML document... This might be easier to fix than I thought 🤔

image

cscheid commented 1 year ago

fwiw, this used to work on 0.1.20. (Sorry that I don't have a tighter bracket for your bisecting...)

b-fuze commented 1 year ago

I'll look into it, thanks