window.location.replace with invalid urls should throw
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Jun 2020 08:04:12 +0000 (08:04 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 29 Jun 2020 08:04:12 +0000 (08:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=153121

Patch by Rob Buis <rbuis@igalia.com> on 2020-06-29
Reviewed by Darin Adler.

LayoutTests/imported/w3c:

Add a subtest to verify that location.replace throws SyntaxError if
the resulting url is not valid.

* web-platform-tests/html/browsers/history/the-location-interface/location_replace-expected.txt:
* web-platform-tests/html/browsers/history/the-location-interface/location_replace.html:

Source/WebCore:

Throw SyntaxError if the url resulting from the
location.replace operation is not valid.

Behavior matches Firefox and Chrome.

Tests: imported/w3c/web-platform-tests/html/browsers/history/the-location-interface/location_replace.html

[1] https://html.spec.whatwg.org/multipage/history.html#dom-location-replace

* page/Location.cpp:
(WebCore::Location::replace):
* page/Location.h:
* page/Location.idl:

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

LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/html/browsers/history/the-location-interface/location_replace-expected.txt
LayoutTests/imported/w3c/web-platform-tests/html/browsers/history/the-location-interface/location_replace.html
Source/WebCore/ChangeLog
Source/WebCore/page/Location.cpp
Source/WebCore/page/Location.h
Source/WebCore/page/Location.idl

index 57300c4..23fc1c1 100644 (file)
@@ -1,3 +1,16 @@
+2020-06-29  Rob Buis  <rbuis@igalia.com>
+
+        window.location.replace with invalid urls should throw
+        https://bugs.webkit.org/show_bug.cgi?id=153121
+
+        Reviewed by Darin Adler.
+
+        Add a subtest to verify that location.replace throws SyntaxError if
+        the resulting url is not valid.
+
+        * web-platform-tests/html/browsers/history/the-location-interface/location_replace-expected.txt:
+        * web-platform-tests/html/browsers/history/the-location-interface/location_replace.html:
+
 2020-06-29  Pinki Gyanchandani  <pgyanchandani@apple.com>
 
         Add a new Web Platform Test in LayoutTest/imported/w3c/web-platform-tests/dom/ranges
index 2f2d573..0593420 100644 (file)
       assert_equals((href + "#x"), location.href, "location href");
 
     }, "location replace");
+
+    test(function () {
+      var href = location.href;
+      assert_throws_dom('SYNTAX_ERR', function() { location.replace("//"); });
+      assert_equals(location.href, href);
+    }, "URL that fails to parse");
     </script>
   </body>
 </html>
index 9fec216..0b0b417 100644 (file)
@@ -1,3 +1,24 @@
+2020-06-29  Rob Buis  <rbuis@igalia.com>
+
+        window.location.replace with invalid urls should throw
+        https://bugs.webkit.org/show_bug.cgi?id=153121
+
+        Reviewed by Darin Adler.
+
+        Throw SyntaxError if the url resulting from the
+        location.replace operation is not valid.
+
+        Behavior matches Firefox and Chrome.
+
+        Tests: imported/w3c/web-platform-tests/html/browsers/history/the-location-interface/location_replace.html
+
+        [1] https://html.spec.whatwg.org/multipage/history.html#dom-location-replace
+
+        * page/Location.cpp:
+        (WebCore::Location::replace):
+        * page/Location.h:
+        * page/Location.idl:
+
 2020-06-28  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][TFC] Adjust table content vertical position to match vertical-align
index 0ba8e6b..32e7497 100644 (file)
@@ -216,25 +216,25 @@ ExceptionOr<void> Location::assign(DOMWindow& activeWindow, DOMWindow& firstWind
     return setLocation(activeWindow, firstWindow, url);
 }
 
-void Location::replace(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& urlString)
+ExceptionOr<void> Location::replace(DOMWindow& activeWindow, DOMWindow& firstWindow, const String& urlString)
 {
     auto* frame = this->frame();
     if (!frame)
-        return;
+        return { };
     ASSERT(frame->document());
     ASSERT(frame->document()->domWindow());
 
     Frame* firstFrame = firstWindow.frame();
     if (!firstFrame || !firstFrame->document())
-        return;
+        return { };
 
     URL completedURL = firstFrame->document()->completeURL(urlString);
-    // FIXME: The specification says to throw a SyntaxError if the URL is not valid.
-    if (completedURL.isNull())
-        return;
+    if (!completedURL.isValid())
+        return Exception { SyntaxError };
 
     // We call DOMWindow::setLocation directly here because replace() always operates on the current frame.
     frame->document()->domWindow()->setLocation(activeWindow, completedURL, LockHistoryAndBackForwardList);
+    return { };
 }
 
 void Location::reload(DOMWindow& activeWindow)
index ba104dc..49dbf75 100644 (file)
@@ -46,7 +46,7 @@ public:
     String href() const;
 
     ExceptionOr<void> assign(DOMWindow& activeWindow, DOMWindow& firstWindow, const String&);
-    void replace(DOMWindow& activeWindow, DOMWindow& firstWindow, const String&);
+    ExceptionOr<void> replace(DOMWindow& activeWindow, DOMWindow& firstWindow, const String&);
     void reload(DOMWindow& activeWindow);
 
     ExceptionOr<void> setProtocol(DOMWindow& activeWindow, DOMWindow& firstWindow, const String&);
index b0dcccd..7fd3469 100644 (file)
@@ -47,7 +47,7 @@
     [SetterCallWith=ActiveWindow&FirstWindow, DoNotCheckSecurityOnSetter] stringifier attribute USVString href;
 
     [CallWith=ActiveWindow&FirstWindow, MayThrowException, ForwardDeclareInHeader] void assign(USVString url);
-    [DoNotCheckSecurity, CallWith=ActiveWindow&FirstWindow, ForwardDeclareInHeader] void replace(USVString url);
+    [DoNotCheckSecurity, CallWith=ActiveWindow&FirstWindow, MayThrowException, ForwardDeclareInHeader] void replace(USVString url);
     [CallWith=ActiveWindow, ForwardDeclareInHeader] void reload();
 
     // URI decomposition attributes