Fix null handling of several Document attributes
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Jul 2016 03:30:48 +0000 (03:30 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Jul 2016 03:30:48 +0000 (03:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159997

Reviewed by Ryosuke Niwa.

Source/WebCore:

Fix null handling of the following Document attributes: title, cookie
and domain.

In WebKit, they were all marked as [TreatNullAs=EmptyString], which
does not match the specification:
- https://html.spec.whatwg.org/multipage/dom.html#document

Details for each attribute:
- title: null is now treated as the string "null", thus setting the
  document title to "null". This matches Firefox and Chrome.
- cookie: adds a "null" cookie instead of being a no-op. This matches
          both Firefox and Chrome.
- domain: Calls setDomain(String("null")) instead of
          setDomain(String()). This throws an exception because "null"
          is not a suffix of the effective domain name. The behavior
          is the same in Firefox and Chrome. Previously, we were
          already throwing an exception since setting the domain to
          the empty string throws, as per the specification.

Test: http/tests//dom/document-attributes-null-handling.html

* dom/Document.idl:

LayoutTests:

Add test coverage.

* http/tests/dom/document-attributes-null-handling-expected.txt: Added.
* http/tests/dom/document-attributes-null-handling.html: Added.
* fast/dom/document-attribute-js-null-expected.txt:
* fast/dom/document-attribute-js-null.html:

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/document-attribute-js-null-expected.txt
LayoutTests/fast/dom/document-attribute-js-null.html
LayoutTests/http/tests/dom/document-attributes-null-handling-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/dom/document-attributes-null-handling.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.idl

index 3ee4536..749089b 100644 (file)
@@ -1,3 +1,17 @@
+2016-07-20  Chris Dumez  <cdumez@apple.com>
+
+        Fix null handling of several Document attributes
+        https://bugs.webkit.org/show_bug.cgi?id=159997
+
+        Reviewed by Ryosuke Niwa.
+
+        Add test coverage.
+
+        * http/tests/dom/document-attributes-null-handling-expected.txt: Added.
+        * http/tests/dom/document-attributes-null-handling.html: Added.
+        * fast/dom/document-attribute-js-null-expected.txt:
+        * fast/dom/document-attribute-js-null.html:
+
 2016-07-20  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r203471.
index bb2c0fc..72100f7 100644 (file)
@@ -3,7 +3,7 @@ This test setting various attributes of documents to JavaScript null.
 TEST SUCCEEDED: Got the expected exception (9). [tested Document.xmlVersion]
 TEST SUCCEEDED: The value was null. [tested Document.selectedStylesheetSet]
 
-TEST SUCCEEDED: The value was the empty string. [tested HTMLDocument.title]
+TEST SUCCEEDED: The value was the string 'null'. [tested HTMLDocument.title]
 TEST SUCCEEDED: The value was the empty string. [tested HTMLDocument.cookie]
 TEST SUCCEEDED: The value was the empty string. [tested HTMLDocument.bgColor]
 TEST SUCCEEDED: The value was the empty string. [tested HTMLDocument.fgColor]
index 9a4e740..7bc218b 100644 (file)
@@ -72,7 +72,7 @@
                     typeName: 'HTMLDocument',
                     docToUse: htmlDoc,
                     attributes: [
-                        {name: 'title', expectedNull: ''},
+                        {name: 'title', expectedNull: 'null'},
                         {name: 'cookie', expectedNull: ''},
                         {name: 'bgColor', expectedNull: ''},
                         {name: 'fgColor', expectedNull: ''},
diff --git a/LayoutTests/http/tests/dom/document-attributes-null-handling-expected.txt b/LayoutTests/http/tests/dom/document-attributes-null-handling-expected.txt
new file mode 100644 (file)
index 0000000..14bf4e1
--- /dev/null
@@ -0,0 +1,25 @@
+Test null handling of several Document attributes
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+* cookie attribute
+PASS document.cookie is ""
+document.cookie = 'key=value'
+PASS document.cookie is "key=value"
+document.cookie = null
+PASS document.cookie is "key=value; null="
+
+* title attribute
+PASS document.title is ""
+document.title = null
+PASS document.title is "null"
+
+* domain attribute
+PASS document.domain is "127.0.0.1"
+PASS document.domain = null threw exception SecurityError (DOM Exception 18): The operation is insecure..
+PASS document.domain is "127.0.0.1"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/dom/document-attributes-null-handling.html b/LayoutTests/http/tests/dom/document-attributes-null-handling.html
new file mode 100644 (file)
index 0000000..8d0bcc9
--- /dev/null
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="/js-test-resources/js-test-pre.js"></script>
+<script>
+description("Test null handling of several Document attributes");
+
+debug("* cookie attribute");
+shouldBeEqualToString("document.cookie", "");
+evalAndLog("document.cookie = 'key=value'");
+shouldBeEqualToString("document.cookie", "key=value");
+evalAndLog("document.cookie = null");
+shouldBeEqualToString("document.cookie", "key=value; null=");
+
+debug("");
+debug("* title attribute");
+shouldBeEqualToString("document.title", "");
+evalAndLog("document.title = null");
+shouldBeEqualToString("document.title", "null");
+
+debug("");
+debug("* domain attribute");
+shouldBeEqualToString("document.domain", "127.0.0.1");
+shouldThrow("document.domain = null");
+shouldBeEqualToString("document.domain", "127.0.0.1");
+</script>
+<script src="/js-test-resources/js-test-post.js"></script>
+</body>
+</html>
index 6ab05c1..fb72558 100644 (file)
@@ -1,3 +1,33 @@
+2016-07-20  Chris Dumez  <cdumez@apple.com>
+
+        Fix null handling of several Document attributes
+        https://bugs.webkit.org/show_bug.cgi?id=159997
+
+        Reviewed by Ryosuke Niwa.
+
+        Fix null handling of the following Document attributes: title, cookie
+        and domain.
+
+        In WebKit, they were all marked as [TreatNullAs=EmptyString], which
+        does not match the specification:
+        - https://html.spec.whatwg.org/multipage/dom.html#document
+
+        Details for each attribute:
+        - title: null is now treated as the string "null", thus setting the
+          document title to "null". This matches Firefox and Chrome.
+        - cookie: adds a "null" cookie instead of being a no-op. This matches
+                  both Firefox and Chrome.
+        - domain: Calls setDomain(String("null")) instead of
+                  setDomain(String()). This throws an exception because "null"
+                  is not a suffix of the effective domain name. The behavior
+                  is the same in Firefox and Chrome. Previously, we were
+                  already throwing an exception since setting the domain to
+                  the empty string throws, as per the specification.
+
+        Test: http/tests//dom/document-attributes-null-handling.html
+
+        * dom/Document.idl:
+
 2016-07-20  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r203471.
index 9406c1e..aac91c1 100644 (file)
 
     // Moved down from HTMLDocument
 
-    // FIXME: Should not have [TreatNullAs=EmptyString].
-    [TreatNullAs=EmptyString, SetterRaisesException] attribute DOMString title;
+    [SetterRaisesException] attribute DOMString title;
 
     readonly attribute DOMString referrer;
 #if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
-    // FIXME: Should not have [TreatNullAs=EmptyString].
-    [TreatNullAs=EmptyString, SetterRaisesException] attribute DOMString domain;
+    [SetterRaisesException] attribute DOMString domain;
 #else
     readonly attribute DOMString domain;
 #endif
     [ImplementedAs=urlForBindings] readonly attribute DOMString URL;
 
-    // FIXME: Should not have [TreatNullAs=EmptyString].
-    [TreatNullAs=EmptyString, GetterRaisesException, SetterRaisesException] attribute DOMString cookie;
+    [GetterRaisesException, SetterRaisesException] attribute DOMString cookie;
 
     [SetterRaisesException, ImplementedAs=bodyOrFrameset, StrictTypeChecking] attribute HTMLElement? body;