From 7e179d924525096aa1f7ee0db1c52f8e85533107 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 7 Aug 2015 15:47:55 +0200 Subject: [PATCH] Handle url parse errors in Location#assign more gracefully. --- components/script/dom/location.rs | 7 +++---- .../history/the-location-interface/location_assign.html | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/components/script/dom/location.rs b/components/script/dom/location.rs index 73f7d6f1fe1..69cfb4b7d5b 100644 --- a/components/script/dom/location.rs +++ b/components/script/dom/location.rs @@ -43,10 +43,9 @@ impl<'a> LocationMethods for &'a Location { // TODO: per spec, we should use the _API base URL_ specified by the // _entry settings object_. let base_url = window.get_url(); - let url = UrlParser::new().base_url(&base_url).parse(&url); - // FIXME: handle URL parse errors more gracefully. - let url = url.unwrap(); - window.load_url(url); + if let Ok(url) = UrlParser::new().base_url(&base_url).parse(&url) { + window.load_url(url); + } } // https://url.spec.whatwg.org/#dom-urlutils-hash diff --git a/tests/wpt/web-platform-tests/html/browsers/history/the-location-interface/location_assign.html b/tests/wpt/web-platform-tests/html/browsers/history/the-location-interface/location_assign.html index 6f7da1a5332..a2d6e0fb820 100644 --- a/tests/wpt/web-platform-tests/html/browsers/history/the-location-interface/location_assign.html +++ b/tests/wpt/web-platform-tests/html/browsers/history/the-location-interface/location_assign.html @@ -15,6 +15,12 @@ assert_equals((href + "#x"), location.href, "location href"); }, "location assign"); + + test(function () { + var href = location.href; + location.assign("http://:"); + assert_equals(location.href, href); + }, "URL that fails to parse");