script.text shouldn't include text from non-direct children of the script element
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Oct 2015 02:26:13 +0000 (02:26 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Oct 2015 02:26:13 +0000 (02:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148851
<rdar://problem/22587759>

Patch by Keith Rollin <krollin@apple.com> on 2015-10-07
Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

Rebaseline several W3C HTML tests now that new checks are passing.

* web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-expected.txt:
* web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-xhtml-expected.txt:

Source/WebCore:

Don't include text from non-direct children in script.text. Per:
https://html.spec.whatwg.org/multipage/scripting.html#dom-script-text
Chrome and Firefox behavior match the spec.

Test: fast/dom/script-subtext-in-script-elements.html

* dom/ScriptElement.cpp:
(WebCore::ScriptElement::scriptContent):

LayoutTests:

script-getElementById-during-insertion removed because it no longer
runs correctly with this change.

* fast/dom/script-getElementById-during-insertion-expected.txt: Removed.
* fast/dom/script-getElementById-during-insertion.html: Removed.
* fast/dom/script-subtext-in-script-elements-expected.txt: Added.
* fast/dom/script-subtext-in-script-elements.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190703 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/script-getElementById-during-insertion-expected.txt [deleted file]
LayoutTests/fast/dom/script-getElementById-during-insertion.html [deleted file]
LayoutTests/fast/dom/script-subtext-in-script-elements-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/script-subtext-in-script-elements.html [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-expected.txt
LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-xhtml-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/dom/ScriptElement.cpp

index 103fe7cc823dec3614166a1b45d1df94efa970f0..66addfaac1728ea78cede8188dfabc2d8646b83a 100644 (file)
@@ -1,3 +1,19 @@
+2015-10-07  Keith Rollin  <krollin@apple.com>
+
+        script.text shouldn't include text from non-direct children of the script element
+        https://bugs.webkit.org/show_bug.cgi?id=148851
+        <rdar://problem/22587759>
+
+        Reviewed by Chris Dumez.
+
+        script-getElementById-during-insertion removed because it no longer
+        runs correctly with this change.
+
+        * fast/dom/script-getElementById-during-insertion-expected.txt: Removed.
+        * fast/dom/script-getElementById-during-insertion.html: Removed.
+        * fast/dom/script-subtext-in-script-elements-expected.txt: Added.
+        * fast/dom/script-subtext-in-script-elements.html: Added.
+
 2015-10-07  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Test font-variant-* and font-feature-settings with TrueType fonts
 2015-10-07  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Test font-variant-* and font-feature-settings with TrueType fonts
diff --git a/LayoutTests/fast/dom/script-getElementById-during-insertion-expected.txt b/LayoutTests/fast/dom/script-getElementById-during-insertion-expected.txt
deleted file mode 100644 (file)
index 69cfc5a..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-PASS
-
diff --git a/LayoutTests/fast/dom/script-getElementById-during-insertion.html b/LayoutTests/fast/dom/script-getElementById-during-insertion.html
deleted file mode 100644 (file)
index 4f3a93a..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<script>
-// Tests that we don't crash if a script is being executed as a result of appending a child to it.</p>
-executedScript = false;
-if (window.testRunner)
-  testRunner.dumpAsText();
-</script>
-</head>
-<body>
-<div id="test"></div>
-<script>
-var elem = document.getElementById("test");
-if (!executedScript) {
-    executedScript = true;
-
-    document.documentElement.appendChild(elem.cloneNode(true));
-
-    var range = document.createRange();
-    range.setStartBefore(document.body);
-    range.setEndAfter(document.body);
-    range.surroundContents(document.head.appendChild(document.createElement("script")));
-} else {
-    var span = document.createElement("span");
-    document.documentElement.appendChild(span);
-    span.innerHTML = 'PASS<br/>';
-}
-</script>
-</body>
-</html>
diff --git a/LayoutTests/fast/dom/script-subtext-in-script-elements-expected.txt b/LayoutTests/fast/dom/script-subtext-in-script-elements-expected.txt
new file mode 100644 (file)
index 0000000..bdb0bf7
--- /dev/null
@@ -0,0 +1,3 @@
+Ensure that Text nodes that are not direct children of Script elements are not included for execution.
+
+PASS
diff --git a/LayoutTests/fast/dom/script-subtext-in-script-elements.html b/LayoutTests/fast/dom/script-subtext-in-script-elements.html
new file mode 100644 (file)
index 0000000..9c798ff
--- /dev/null
@@ -0,0 +1,23 @@
+<html>
+<head>
+<script>
+if (window.testRunner)
+  testRunner.dumpAsText();
+</script>
+</head>
+
+<body>
+    <p>Ensure that Text nodes that are not direct children of Script elements are not included for execution.</p>
+    <div id="result">FAIL</div>
+    <script>
+        // See https://html.spec.whatwg.org/multipage/scripting.html#dom-script-text
+        // See <rdar://problem/22587759> script.text shouldn't include text from non-direct children of the script element (148851)
+
+        var script = document.createElement("script");
+        script.appendChild(document.createTextNode("document.getElementById('result').innerHTML = 'PASS';"));
+        var div = script.appendChild(document.createElement("div"));
+        div.appendChild(document.createTextNode("document.getElementById('result').innerHTML = 'FAIL';"))
+        document.body.appendChild(script);
+    </script>
+</body>
+</html>
index e3cc0704d4031fc05d3a83288bbde62a8fc94647..8e9be723124fb0a786234e05e7780e94d4a19c78 100644 (file)
@@ -1,3 +1,16 @@
+2015-10-07  Keith Rollin  <krollin@apple.com>
+
+        script.text shouldn't include text from non-direct children of the script element
+        https://bugs.webkit.org/show_bug.cgi?id=148851
+        <rdar://problem/22587759>
+
+        Reviewed by Chris Dumez.
+
+        Rebaseline several W3C HTML tests now that new checks are passing.
+
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-expected.txt:
+        * web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-xhtml-expected.txt:
+
 2015-10-06  Chris Dumez  <cdumez@apple.com>
 
         [Web IDL] 'length' property is wrong for variadic operations
 2015-10-06  Chris Dumez  <cdumez@apple.com>
 
         [Web IDL] 'length' property is wrong for variadic operations
index e5edb3000cabd72880aa495ad1a19cc20abccb42..32e0d31ed36ee4dd8a6516f11daf7ab267ad0bfe 100644 (file)
@@ -1,5 +1,5 @@
 
 
-FAIL Getter assert_equals: expected "  TEXT  " but got "  TEXT  ELEMENT"
+PASS Getter 
 PASS Setter (non-empty string) 
 FAIL Setter (empty string) assert_equals: expected null but got Text node ""
 FAIL Setter (null) assert_equals: expected "null" but got ""
 PASS Setter (non-empty string) 
 FAIL Setter (empty string) assert_equals: expected null but got Text node ""
 FAIL Setter (null) assert_equals: expected "null" but got ""
index b0cce006a6040f05482e844f6ce557fa63440ffd..519c194c71b876b652293d65a4db254fb9a44d09 100644 (file)
@@ -1,3 +1,3 @@
 
 
-FAIL Getter with CDATA section assert_equals: expected "\n\n\n  var x = \"y\";\n\n" but got "\n7;\n\n  var x = \"y\";\n\n"
+PASS Getter with CDATA section 
 
 
index 69ef49a677807869e3df67d187bfcb09b1cd8044..f2cbd058a922d633a577676b39ed11255aa0cdba 100644 (file)
@@ -1,3 +1,20 @@
+2015-10-07  Keith Rollin  <krollin@apple.com>
+
+        script.text shouldn't include text from non-direct children of the script element
+        https://bugs.webkit.org/show_bug.cgi?id=148851
+        <rdar://problem/22587759>
+
+        Reviewed by Chris Dumez.
+
+        Don't include text from non-direct children in script.text. Per:
+        https://html.spec.whatwg.org/multipage/scripting.html#dom-script-text
+        Chrome and Firefox behavior match the spec.
+
+        Test: fast/dom/script-subtext-in-script-elements.html
+
+        * dom/ScriptElement.cpp:
+        (WebCore::ScriptElement::scriptContent):
+
 2015-10-07  Chris Dumez  <cdumez@apple.com>
 
         Partial revert of r187626 as it caused a PLT regression
 2015-10-07  Chris Dumez  <cdumez@apple.com>
 
         Partial revert of r187626 as it caused a PLT regression
index 66bbece1d35e1a4763bf9ebebf0f0c12cdbef1d7..eb7974e74893b045ff9de6777d5df7365c2ad45f 100644 (file)
@@ -382,7 +382,10 @@ bool ScriptElement::isScriptForEventSupported() const
 
 String ScriptElement::scriptContent() const
 {
 
 String ScriptElement::scriptContent() const
 {
-    return TextNodeTraversal::contentsAsString(m_element);
+    StringBuilder result;
+    for (auto* text = TextNodeTraversal::firstChild(m_element); text; text = TextNodeTraversal::nextSibling(*text))
+        result.append(text->data());
+    return result.toString();
 }
 
 ScriptElement* toScriptElementIfPossible(Element* element)
 }
 
 ScriptElement* toScriptElementIfPossible(Element* element)