New issue
Advanced search Search tips

Issue 898775 link

Starred by 1 user

Issue metadata

Status: Available
Owner: ----
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Task



Sign in to add a comment

Rationalize DOMParser.parseFromString

Project Member Reported by f...@opera.com, Oct 25

Issue description

(From discussion on https://chromium-review.googlesource.com/c/chromium/src/+/1224791)

In DOMParser.parseFromString when StopParsing has been called (which it will be for instance when we encounter a "broken" attribute), end() will not be called. The reason for this is that it uses Document::SetContent which does open(), <append data>, close() - and close() will return early if the parser is not in the "parsing" state.

Maybe SetContent should use lower level primitives to achieve what it sets out to do, or maybe DOMParser.parseFromString should mimic cases like for instance innerHTML (which is very similar modulo the DocumentFragment.)

One might also argue that Document::close shouldn't be checking the parsing state where it is, and rather just check the "was create by script" flag - which is closer to the speced behavior. This seems like a more general thing though.

Relevant spec starting point:

https://w3c.github.io/DOM-Parsing/#dfn-parsefromstring
 
Project Member

Comment 1 by bugdroid1@chromium.org, Oct 25

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/565958bc22e2d49fed7af144482c2bf4d416fec5

commit 565958bc22e2d49fed7af144482c2bf4d416fec5
Author: Fredrik Söderquist <fs@opera.com>
Date: Thu Oct 25 12:09:25 2018

Insert an error message block when parsing was stopped after an error

The <parsererror> element was not being added to the parsed document in
certain cases involving attribute parsing. For example, if an undeclared
namespace prefix was used in the document, then parsing would stop, but
a <parsererror> element would not be inserted into the document to
indicate that a parsing error occurred.

When XMLDocumentParser::StopParsing() is called to stop parsing, call
InsertErrorMessageBlock() to insert the <parsererror> element if an
error occurred.

Based on https://codereview.chromium.org/771493002/ by dtrebbien@gmail.com

Bug:  295809 , 898775
Change-Id: Ic67a3ab885fae4b01ca92f6d927b3f523f7423ed
Reviewed-on: https://chromium-review.googlesource.com/c/1224791
Commit-Queue: Fredrik Söderquist <fs@opera.com>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602674}
[add] https://crrev.com/565958bc22e2d49fed7af144482c2bf4d416fec5/third_party/WebKit/LayoutTests/external/wpt/domparsing/DOMParser-parseFromString-xml-parsererror.html
[modify] https://crrev.com/565958bc22e2d49fed7af144482c2bf4d416fec5/third_party/blink/renderer/core/xml/parser/xml_document_parser.cc

Sign in to add a comment