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");