Closed Bug 1087715 Opened 6 years ago Closed 6 years ago

Range.createContextualFragment() parses SVG unexpectedly

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 886390

People

(Reporter: dtrebbien, Unassigned)

Details

Range.createContextualFragment() creates a DocumentFragment that is not as expected when the context is an SVG element.

For example:

    range.createContextualFragment("<linearGradient id='lg1'/><linearGradient id='lg2'/>");

.. creates the following DOM tree in Firefox 33.0 and Firefox Nightly 36.0a1 (2014-10-22):

    <linearGradient id='lg1'>
      <linearGradient id='lg2'/>
    </linearGradient>

See this jsFiddle for a complete test case: http://jsfiddle.net/hfvz7srp/
In Firefox, the alert dialog will say '1' instead of the expected '2'.

This test case works as expected in Chrome 38.0.2125.104 (Official Build 290379), and the parsed DOM tree is:

    <linearGradient id='lg1'/>
    <linearGradient id='lg2'/>

IE11 behaves the same as Firefox.
Anne, what does the spec says here?  I see nothing special-casing SVG in the fragment parsing algorithm....
Flags: needinfo?(annevk)
This is a bug in Chrome. Might be worth adding a testcase someplace.

The problem with this particular demo is that <defs> following an <html> start tag (see https://html.spec.whatwg.org/multipage/syntax.html#html-fragment-parsing-algorithm for details) will not create a foreign element. <defs> is the context per https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#widl-Range-createContextualFragment-DocumentFragment-DOMString-fragment

It works fine in Firefox if the context is <svg>.
Flags: needinfo?(annevk)
Oh, yes. I see from following the parsing algorithm through, that the <lineargradient> elements would be created in the HTML namespace rather than the SVG namespace anyway, which is probably not what I want. Indeed, Firefox sets the namespace URI on the <lineargradient> elements to "http://www.w3.org/1999/xhtml".

The <lineargradient> elements parsed by Chrome have namespace URI "http://www.w3.org/2000/svg", which is technically not correct according to the current parsing algorithm when the context is a <defs> element.
Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Resolution: --- → INVALID
I updated the jsFiddle to use the <svg> element as the context element and I still see '1':
http://jsfiddle.net/hfvz7srp/1/

What am I missing?
I missed something. That seems like a bug.
Status: RESOLVED → REOPENED
Ever confirmed: true
Flags: needinfo?(hsivonen)
Resolution: INVALID → ---
Bug 886390 hasn't landed yet, so one should assume parsing with a foreign context node to be broken.
Flags: needinfo?(hsivonen)
Can mark this as duplicate if that bug turns out to fix this.
Depends on: 886390
Status: REOPENED → RESOLVED
Closed: 6 years ago6 years ago
No longer depends on: 886390
Resolution: --- → DUPLICATE
Duplicate of bug: 886390
You need to log in before you can comment on or make changes to this bug.