Skip to content

XML error behavior for parseFromString() causing compat issues #11373

Open
@emilio

Description

@emilio

What is the issue with the HTML Standard?

The spec for DOMParser.parseFromString says that, for the error case:

If the previous step resulted in an XML well-formedness or XML namespace well-formedness error, then:

That matches what Gecko does, but it seems WebKit and Blink do a bit weirder error recovery.

  • They keep the partially parsed page, and insert as the first node under the document element the error message, which is not a custom namespace but a regular HTML element.
  • For SVG they do something even weirder.

We've found a couple (somewhat minor, but still) compat issues that are caused by this. In the last one, the page ends up parsing an HTML 404 page, and the JS code follows the spec and checks that document.documentElement.nodeName == "parsererror", thus firing an error. This is arguably a bug on the site, but it happened to work with Blink / WebKit's implementation because they preserve the root element from the original page, so the page doesn't detect the 404 error :').

I'm not a huge fan of what Blink / WebKit are doing, but it'd be nice to decide if we keep the spec and Firefox as is (and fix Blink / WebKit), or change the spec and Firefox.

Metadata

Metadata

Assignees

No one assigned

    Labels

    interopImplementations are not interoperable with each othertopic: parser

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions