Skip to content
Permalink
Browse files
document.createProcessingInstruction() does not behave according to s…
…pecification

https://bugs.webkit.org/show_bug.cgi?id=148710

Reviewed by Ryosuke Niwa.

Source/WebCore:

document.createProcessingInstruction() does not behave according to
specification:
https://dom.spec.whatwg.org/#dom-document-createprocessinginstruction

The following changes were made in this patch to match the specification
and the behavior of Firefox / Chrome:
1. document.createProcessingInstruction() now works for HTML documents.
2. Throw an InvalidCharacterError if the data contains "?>" (step 2 of spec)

No new tests, already covered by existing tests that are rebaselined in
this patch.

* dom/Document.cpp:
(WebCore::Document::createProcessingInstruction):

LayoutTests:

Update / rebaseline existing tests.

* dom/html/level1/core/documentinvalidcharacterexceptioncreatepi-expected.txt:
* dom/html/level1/core/documentinvalidcharacterexceptioncreatepi1-expected.txt:
* fast/dom/Node/initial-values-expected.txt:
* fast/dom/Node/script-tests/initial-values.js:
* http/tests/w3c/dom/nodes/CharacterData-remove-expected.txt:
* http/tests/w3c/dom/nodes/Document-createProcessingInstruction-expected.txt:
* http/tests/w3c/dom/nodes/Document-createProcessingInstruction-xhtml-expected.txt:
* http/tests/w3c/dom/nodes/Node-cloneNode-expected.txt:
* http/tests/w3c/dom/nodes/Node-insertBefore-expected.txt:
* http/tests/w3c/dom/nodes/Node-nodeValue-expected.txt:
* http/tests/w3c/dom/nodes/Node-textContent-expected.txt:

Canonical link: https://commits.webkit.org/166831@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189253 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
cdumez committed Sep 2, 2015
1 parent 659601e commit d9f6a6edff83dec26af2f6274b1361a43e136fc6
Showing 14 changed files with 121 additions and 56 deletions.
@@ -1,3 +1,24 @@
2015-09-02 Chris Dumez <cdumez@apple.com>

document.createProcessingInstruction() does not behave according to specification
https://bugs.webkit.org/show_bug.cgi?id=148710

Reviewed by Ryosuke Niwa.

Update / rebaseline existing tests.

* dom/html/level1/core/documentinvalidcharacterexceptioncreatepi-expected.txt:
* dom/html/level1/core/documentinvalidcharacterexceptioncreatepi1-expected.txt:
* fast/dom/Node/initial-values-expected.txt:
* fast/dom/Node/script-tests/initial-values.js:
* http/tests/w3c/dom/nodes/CharacterData-remove-expected.txt:
* http/tests/w3c/dom/nodes/Document-createProcessingInstruction-expected.txt:
* http/tests/w3c/dom/nodes/Document-createProcessingInstruction-xhtml-expected.txt:
* http/tests/w3c/dom/nodes/Node-cloneNode-expected.txt:
* http/tests/w3c/dom/nodes/Node-insertBefore-expected.txt:
* http/tests/w3c/dom/nodes/Node-nodeValue-expected.txt:
* http/tests/w3c/dom/nodes/Node-textContent-expected.txt:

2015-09-02 Chris Dumez <cdumez@apple.com>

http/tests/w3c/dom/nodes/Element-matches.html is flaky
@@ -1,2 +1,3 @@
Test: http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreatepi
Status: Success
Test: http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreatepi
Status: failure
Detail: throw_NOT_SUPPORTED_ERR: assertTrue failed
@@ -1,2 +1,3 @@
Test: http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreatepi1
Status: Success
Test: http://www.w3.org/2001/DOM-Test-Suite/level1/core/documentinvalidcharacterexceptioncreatepi1
Status: failure
Detail: throw_NOT_SUPPORTED_ERR: assertTrue failed
@@ -119,7 +119,10 @@ PASS entityReference.localName is null
PASS entityReference.namespaceURI is null
PASS entityReference.prefix is null
PASS entityReference.nodeValue is null
PASS document.createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="missing.xsl"') threw exception Error: NotSupportedError: DOM Exception 9.
PASS processingInstruction.nodeName is 'xml-stylesheet'
PASS processingInstruction.localName is null
PASS processingInstruction.namespaceURI is null
PASS processingInstruction.prefix is null
PASS processingInstruction.nodeName is 'xml-stylesheet'
PASS processingInstruction.localName is null
PASS processingInstruction.namespaceURI is null
@@ -168,8 +168,13 @@ shouldBe("entityReference.nodeValue", "null");

// Not possible to create Notation nodes via the DOM, WebKit doesn't create them from parsing

shouldThrow("document.createProcessingInstruction('xml-stylesheet', 'type=\"text/xsl\" href=\"missing.xsl\"')");
var processingInstruction = xmlDoc.createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="missing.xsl"');
var processingInstruction = document.createProcessingInstruction('xml-stylesheet', 'type=\"text/xsl\" href=\"missing.xsl\"');
shouldBe("processingInstruction.nodeName", "'xml-stylesheet'");
shouldBe("processingInstruction.localName", "null");
shouldBe("processingInstruction.namespaceURI", "null");
shouldBe("processingInstruction.prefix", "null");

processingInstruction = xmlDoc.createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="missing.xsl"');
shouldBe("processingInstruction.nodeName", "'xml-stylesheet'");
shouldBe("processingInstruction.localName", "null");
shouldBe("processingInstruction.namespaceURI", "null");
@@ -1,2 +1,14 @@

Harness Error. harness_status.status = 1 , harness_status.message = Error: NotSupportedError: DOM Exception 9
PASS text should support remove()
PASS remove() should work if text doesn't have a parent
PASS remove() should work if text does have a parent
PASS remove() should work if text does have a parent and siblings
PASS comment should support remove()
PASS remove() should work if comment doesn't have a parent
PASS remove() should work if comment does have a parent
PASS remove() should work if comment does have a parent and siblings
PASS PI should support remove()
PASS remove() should work if PI doesn't have a parent
PASS remove() should work if PI does have a parent
PASS remove() should work if PI does have a parent and siblings

@@ -1,15 +1,14 @@

PASS Document.createProcessingInstruction in HTML documents
FAIL Should throw an INVALID_CHARACTER_ERR for target "A" and data "?>". assert_throws: function "function () {
document.createProcessingInstructio..." threw object "Error: NotSupportedError: DOM Exception 9" that is not a DOMException INVALID_CHARACTER_ERR: property "code" is equal to 9, expected 5
PASS Should throw an INVALID_CHARACTER_ERR for target "A" and data "?>".
PASS Should throw an INVALID_CHARACTER_ERR for target "·A" and data "x".
PASS Should throw an INVALID_CHARACTER_ERR for target "×A" and data "x".
PASS Should throw an INVALID_CHARACTER_ERR for target "A×" and data "x".
PASS Should throw an INVALID_CHARACTER_ERR for target "\\A" and data "x".
PASS Should throw an INVALID_CHARACTER_ERR for target "\f" and data "x".
PASS Should throw an INVALID_CHARACTER_ERR for target 0 and data "x".
PASS Should throw an INVALID_CHARACTER_ERR for target "0" and data "x".
FAIL Should get a ProcessingInstruction for target "xml:fail" and data "x". NotSupportedError: DOM Exception 9
FAIL Should get a ProcessingInstruction for target "A·A" and data "x". NotSupportedError: DOM Exception 9
FAIL Should get a ProcessingInstruction for target "a0" and data "x". NotSupportedError: DOM Exception 9
PASS Should get a ProcessingInstruction for target "xml:fail" and data "x".
PASS Should get a ProcessingInstruction for target "A·A" and data "x".
PASS Should get a ProcessingInstruction for target "a0" and data "x".

@@ -1,7 +1,6 @@

PASS Document.createProcessingInstruction in XML documents
FAIL Should throw an INVALID_CHARACTER_ERR for target "A" and data "?>". assert_throws: function "function () {
document.createProcessingInstructio..." did not throw
PASS Should throw an INVALID_CHARACTER_ERR for target "A" and data "?>".
PASS Should throw an INVALID_CHARACTER_ERR for target "·A" and data "x".
PASS Should throw an INVALID_CHARACTER_ERR for target "×A" and data "x".
PASS Should throw an INVALID_CHARACTER_ERR for target "A×" and data "x".
@@ -32,7 +32,7 @@ PASS createComment
PASS createElement with attributes
PASS createElementNS HTML
PASS createElementNS non-HTML
FAIL createProcessingInstruction NotSupportedError: DOM Exception 9
PASS createProcessingInstruction
PASS implementation.createDocumentType
PASS implementation.createDocument
FAIL implementation.createHTMLDocument assert_equals: expected "" but got "title"
@@ -6,8 +6,8 @@ FAIL Calling insertBefore with a non-Node first argument on a leaf node Text mus
PASS Calling insertBefore an a leaf node Text must throw HIERARCHY_REQUEST_ERR.
FAIL Calling insertBefore with a non-Node first argument on a leaf node Comment must throw TypeError. assert_throws: function "function () { node.insertBefore(null, null) }" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
PASS Calling insertBefore an a leaf node Comment must throw HIERARCHY_REQUEST_ERR.
FAIL Calling insertBefore with a non-Node first argument on a leaf node ProcessingInstruction must throw TypeError. NotSupportedError: DOM Exception 9
FAIL Calling insertBefore an a leaf node ProcessingInstruction must throw HIERARCHY_REQUEST_ERR. NotSupportedError: DOM Exception 9
FAIL Calling insertBefore with a non-Node first argument on a leaf node ProcessingInstruction must throw TypeError. assert_throws: function "function () { node.insertBefore(null, null) }" threw object "Error: HierarchyRequestError: DOM Exception 3" ("HierarchyRequestError") expected object "TypeError" ("TypeError")
PASS Calling insertBefore an a leaf node ProcessingInstruction must throw HIERARCHY_REQUEST_ERR.
PASS Calling insertBefore with an inclusive ancestor of the context object must throw HIERARCHY_REQUEST_ERR.
PASS Calling insertBefore with a reference child whose parent is not the context node must throw a NotFoundError.
PASS If the context node is a document, inserting a document or text node should throw a HierarchyRequestError.
@@ -1,7 +1,7 @@

PASS Text.nodeValue
PASS Comment.nodeValue
FAIL ProcessingInstruction.nodeValue NotSupportedError: DOM Exception 9
PASS ProcessingInstruction.nodeValue
PASS Element.nodeValue
PASS Document.nodeValue
PASS DocumentFragment.nodeValue
@@ -1,15 +1,15 @@

PASS For an empty Element, textContent should be the empty string
PASS For an empty DocumentFragment, textContent should be the empty string
FAIL Element with children NotSupportedError: DOM Exception 9
FAIL Element with descendants NotSupportedError: DOM Exception 9
FAIL DocumentFragment with children NotSupportedError: DOM Exception 9
FAIL DocumentFragment with descendants NotSupportedError: DOM Exception 9
PASS Element with children
PASS Element with descendants
PASS DocumentFragment with children
PASS DocumentFragment with descendants
PASS For an empty Text, textContent should be the empty string
FAIL For an empty ProcessingInstruction, textContent should be the empty string NotSupportedError: DOM Exception 9
PASS For an empty ProcessingInstruction, textContent should be the empty string
PASS For an empty Comment, textContent should be the empty string
PASS For a Text with data, textContent should be that data
FAIL For a ProcessingInstruction with data, textContent should be that data NotSupportedError: DOM Exception 9
PASS For a ProcessingInstruction with data, textContent should be that data
PASS For a Comment with data, textContent should be that data
PASS For Documents created by parser, textContent should be null
PASS For Documents created by createDocument, textContent should be null
@@ -18,62 +18,62 @@ PASS For DocumentType created by parser, textContent should be null
PASS For DocumentType created by script, textContent should be null
PASS Element without children set to null
PASS Element with empty text node as child set to null
FAIL Element with children set to null NotSupportedError: DOM Exception 9
FAIL Element with descendants set to null NotSupportedError: DOM Exception 9
PASS Element with children set to null
PASS Element with descendants set to null
PASS DocumentFragment without children set to null
PASS DocumentFragment with empty text node as child set to null
FAIL DocumentFragment with children set to null NotSupportedError: DOM Exception 9
FAIL DocumentFragment with descendants set to null NotSupportedError: DOM Exception 9
PASS DocumentFragment with children set to null
PASS DocumentFragment with descendants set to null
FAIL Element without children set to undefined assert_equals: expected "" but got "undefined"
FAIL Element with empty text node as child set to undefined assert_equals: expected "" but got "undefined"
FAIL Element with children set to undefined NotSupportedError: DOM Exception 9
FAIL Element with descendants set to undefined NotSupportedError: DOM Exception 9
FAIL Element with children set to undefined assert_equals: expected "" but got "undefined"
FAIL Element with descendants set to undefined assert_equals: expected "" but got "undefined"
FAIL DocumentFragment without children set to undefined assert_equals: expected "" but got "undefined"
FAIL DocumentFragment with empty text node as child set to undefined assert_equals: expected "" but got "undefined"
FAIL DocumentFragment with children set to undefined NotSupportedError: DOM Exception 9
FAIL DocumentFragment with descendants set to undefined NotSupportedError: DOM Exception 9
FAIL DocumentFragment with children set to undefined assert_equals: expected "" but got "undefined"
FAIL DocumentFragment with descendants set to undefined assert_equals: expected "" but got "undefined"
PASS Element without children set to ""
PASS Element with empty text node as child set to ""
FAIL Element with children set to "" NotSupportedError: DOM Exception 9
FAIL Element with descendants set to "" NotSupportedError: DOM Exception 9
PASS Element with children set to ""
PASS Element with descendants set to ""
PASS DocumentFragment without children set to ""
PASS DocumentFragment with empty text node as child set to ""
FAIL DocumentFragment with children set to "" NotSupportedError: DOM Exception 9
FAIL DocumentFragment with descendants set to "" NotSupportedError: DOM Exception 9
PASS DocumentFragment with children set to ""
PASS DocumentFragment with descendants set to ""
PASS Element without children set to 42
PASS Element with empty text node as child set to 42
FAIL Element with children set to 42 NotSupportedError: DOM Exception 9
FAIL Element with descendants set to 42 NotSupportedError: DOM Exception 9
PASS Element with children set to 42
PASS Element with descendants set to 42
PASS DocumentFragment without children set to 42
PASS DocumentFragment with empty text node as child set to 42
FAIL DocumentFragment with children set to 42 NotSupportedError: DOM Exception 9
FAIL DocumentFragment with descendants set to 42 NotSupportedError: DOM Exception 9
PASS DocumentFragment with children set to 42
PASS DocumentFragment with descendants set to 42
PASS Element without children set to "abc"
PASS Element with empty text node as child set to "abc"
FAIL Element with children set to "abc" NotSupportedError: DOM Exception 9
FAIL Element with descendants set to "abc" NotSupportedError: DOM Exception 9
PASS Element with children set to "abc"
PASS Element with descendants set to "abc"
PASS DocumentFragment without children set to "abc"
PASS DocumentFragment with empty text node as child set to "abc"
FAIL DocumentFragment with children set to "abc" NotSupportedError: DOM Exception 9
FAIL DocumentFragment with descendants set to "abc" NotSupportedError: DOM Exception 9
PASS DocumentFragment with children set to "abc"
PASS DocumentFragment with descendants set to "abc"
PASS Element without children set to "<b>xyz</b>"
PASS Element with empty text node as child set to "<b>xyz</b>"
FAIL Element with children set to "<b>xyz</b>" NotSupportedError: DOM Exception 9
FAIL Element with descendants set to "<b>xyz</b>" NotSupportedError: DOM Exception 9
PASS Element with children set to "<b>xyz</b>"
PASS Element with descendants set to "<b>xyz</b>"
PASS DocumentFragment without children set to "<b>xyz</b>"
PASS DocumentFragment with empty text node as child set to "<b>xyz</b>"
FAIL DocumentFragment with children set to "<b>xyz</b>" NotSupportedError: DOM Exception 9
FAIL DocumentFragment with descendants set to "<b>xyz</b>" NotSupportedError: DOM Exception 9
PASS DocumentFragment with children set to "<b>xyz</b>"
PASS DocumentFragment with descendants set to "<b>xyz</b>"
PASS Element without children set to "d\0e"
PASS Element with empty text node as child set to "d\0e"
FAIL Element with children set to "d\0e" NotSupportedError: DOM Exception 9
FAIL Element with descendants set to "d\0e" NotSupportedError: DOM Exception 9
PASS Element with children set to "d\0e"
PASS Element with descendants set to "d\0e"
PASS DocumentFragment without children set to "d\0e"
PASS DocumentFragment with empty text node as child set to "d\0e"
FAIL DocumentFragment with children set to "d\0e" NotSupportedError: DOM Exception 9
FAIL DocumentFragment with descendants set to "d\0e" NotSupportedError: DOM Exception 9
PASS DocumentFragment with children set to "d\0e"
PASS DocumentFragment with descendants set to "d\0e"
PASS For a Text, textContent should set the data
FAIL For a ProcessingInstruction, textContent should set the data NotSupportedError: DOM Exception 9
PASS For a ProcessingInstruction, textContent should set the data
PASS For a Comment, textContent should set the data
PASS For Documents created by parser, setting textContent should do nothing
PASS For Documents created by createDocument, setting textContent should do nothing
@@ -1,3 +1,25 @@
2015-09-02 Chris Dumez <cdumez@apple.com>

document.createProcessingInstruction() does not behave according to specification
https://bugs.webkit.org/show_bug.cgi?id=148710

Reviewed by Ryosuke Niwa.

document.createProcessingInstruction() does not behave according to
specification:
https://dom.spec.whatwg.org/#dom-document-createprocessinginstruction

The following changes were made in this patch to match the specification
and the behavior of Firefox / Chrome:
1. document.createProcessingInstruction() now works for HTML documents.
2. Throw an InvalidCharacterError if the data contains "?>" (step 2 of spec)

No new tests, already covered by existing tests that are rebaselined in
this patch.

* dom/Document.cpp:
(WebCore::Document::createProcessingInstruction):

2015-09-02 Chris Dumez <cdumez@apple.com>

http/tests/w3c/dom/nodes/Element-matches.html is flaky
@@ -900,10 +900,12 @@ RefPtr<ProcessingInstruction> Document::createProcessingInstruction(const String
ec = INVALID_CHARACTER_ERR;
return nullptr;
}
if (isHTMLDocument()) {
ec = NOT_SUPPORTED_ERR;

if (data.contains("?>")) {
ec = INVALID_CHARACTER_ERR;
return nullptr;
}

return ProcessingInstruction::create(*this, target, data);
}

0 comments on commit d9f6a6e

Please sign in to comment.