Title: [190703] trunk
Revision
190703
Author
commit-qu...@webkit.org
Date
2015-10-07 19:26:13 -0700 (Wed, 07 Oct 2015)

Log Message

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>

Patch by Keith Rollin <krol...@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.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (190702 => 190703)


--- trunk/LayoutTests/ChangeLog	2015-10-08 02:06:40 UTC (rev 190702)
+++ trunk/LayoutTests/ChangeLog	2015-10-08 02:26:13 UTC (rev 190703)
@@ -1,3 +1,19 @@
+2015-10-07  Keith Rollin  <krol...@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  <mmaxfi...@apple.com>
 
         Test font-variant-* and font-feature-settings with TrueType fonts

Deleted: trunk/LayoutTests/fast/dom/script-getElementById-during-insertion-expected.txt (190702 => 190703)


--- trunk/LayoutTests/fast/dom/script-getElementById-during-insertion-expected.txt	2015-10-08 02:06:40 UTC (rev 190702)
+++ trunk/LayoutTests/fast/dom/script-getElementById-during-insertion-expected.txt	2015-10-08 02:26:13 UTC (rev 190703)
@@ -1,2 +0,0 @@
-PASS
-

Deleted: trunk/LayoutTests/fast/dom/script-getElementById-during-insertion.html (190702 => 190703)


--- trunk/LayoutTests/fast/dom/script-getElementById-during-insertion.html	2015-10-08 02:06:40 UTC (rev 190702)
+++ trunk/LayoutTests/fast/dom/script-getElementById-during-insertion.html	2015-10-08 02:26:13 UTC (rev 190703)
@@ -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>

Added: trunk/LayoutTests/fast/dom/script-subtext-in-script-elements-expected.txt (0 => 190703)


--- trunk/LayoutTests/fast/dom/script-subtext-in-script-elements-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/script-subtext-in-script-elements-expected.txt	2015-10-08 02:26:13 UTC (rev 190703)
@@ -0,0 +1,3 @@
+Ensure that Text nodes that are not direct children of Script elements are not included for execution.
+
+PASS

Added: trunk/LayoutTests/fast/dom/script-subtext-in-script-elements.html (0 => 190703)


--- trunk/LayoutTests/fast/dom/script-subtext-in-script-elements.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/script-subtext-in-script-elements.html	2015-10-08 02:26:13 UTC (rev 190703)
@@ -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>

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (190702 => 190703)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2015-10-08 02:06:40 UTC (rev 190702)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2015-10-08 02:26:13 UTC (rev 190703)
@@ -1,3 +1,16 @@
+2015-10-07  Keith Rollin  <krol...@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  <cdu...@apple.com>
 
         [Web IDL] 'length' property is wrong for variadic operations

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-expected.txt (190702 => 190703)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-expected.txt	2015-10-08 02:06:40 UTC (rev 190702)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-expected.txt	2015-10-08 02:26:13 UTC (rev 190703)
@@ -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 ""

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-xhtml-expected.txt (190702 => 190703)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-xhtml-expected.txt	2015-10-08 02:06:40 UTC (rev 190702)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/scripting-1/the-script-element/script-text-xhtml-expected.txt	2015-10-08 02:26:13 UTC (rev 190703)
@@ -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 
 

Modified: trunk/Source/WebCore/ChangeLog (190702 => 190703)


--- trunk/Source/WebCore/ChangeLog	2015-10-08 02:06:40 UTC (rev 190702)
+++ trunk/Source/WebCore/ChangeLog	2015-10-08 02:26:13 UTC (rev 190703)
@@ -1,3 +1,20 @@
+2015-10-07  Keith Rollin  <krol...@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  <cdu...@apple.com>
 
         Partial revert of r187626 as it caused a PLT regression

Modified: trunk/Source/WebCore/dom/ScriptElement.cpp (190702 => 190703)


--- trunk/Source/WebCore/dom/ScriptElement.cpp	2015-10-08 02:06:40 UTC (rev 190702)
+++ trunk/Source/WebCore/dom/ScriptElement.cpp	2015-10-08 02:26:13 UTC (rev 190703)
@@ -382,7 +382,10 @@
 
 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)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to