From 68c4791c7d5ff71e60ab0edf966e9888a945b1a3 Mon Sep 17 00:00:00 2001 From: Andrew Shu Date: Wed, 18 Apr 2018 13:30:22 -0700 Subject: [PATCH] History: update document URL on pushState/replaceState https://html.spec.whatwg.org/multipage/#dom-history-pushstate Steps 6, 7, 10 --- components/script/dom/history.rs | 44 ++++++++++++++++--- .../the-history-interface/008.html.ini | 7 --- .../the-history-interface/009.html.ini | 13 ------ .../the-history-interface/010.html.ini | 13 ------ .../the-history-interface/011.html.ini | 7 --- .../the-history-interface/012.html.ini | 7 --- .../history_pushstate_err.html.ini | 4 -- .../history_replacestate_err.html.ini | 4 -- .../location_hash.html.ini | 3 -- .../location_search.html.ini | 5 --- .../formAction_document_address.html.ini | 8 ---- 11 files changed, 39 insertions(+), 76 deletions(-) delete mode 100644 tests/wpt/metadata/html/browsers/history/the-history-interface/008.html.ini delete mode 100644 tests/wpt/metadata/html/browsers/history/the-history-interface/009.html.ini delete mode 100644 tests/wpt/metadata/html/browsers/history/the-history-interface/010.html.ini delete mode 100644 tests/wpt/metadata/html/browsers/history/the-history-interface/011.html.ini delete mode 100644 tests/wpt/metadata/html/browsers/history/the-history-interface/012.html.ini delete mode 100644 tests/wpt/metadata/html/browsers/history/the-history-interface/history_pushstate_err.html.ini delete mode 100644 tests/wpt/metadata/html/browsers/history/the-history-interface/history_replacestate_err.html.ini delete mode 100644 tests/wpt/metadata/html/browsers/history/the-location-interface/location_search.html.ini delete mode 100644 tests/wpt/metadata/html/semantics/forms/attributes-common-to-form-controls/formAction_document_address.html.ini diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index b158a9d44fd7..a4ba58863738 100644 --- a/components/script/dom/history.rs +++ b/components/script/dom/history.rs @@ -25,6 +25,7 @@ use net_traits::{CoreResourceMsg, IpcSend}; use profile_traits::ipc; use profile_traits::ipc::channel; use script_traits::ScriptMsg; +use servo_url::ServoUrl; use std::cell::Cell; enum PushOrReplace { @@ -108,7 +109,7 @@ impl History { cx: *mut JSContext, data: HandleValue, _title: DOMString, - _url: Option, + url: Option, push_or_replace: PushOrReplace) -> ErrorResult { // Step 1 let document = self.window.Document(); @@ -126,8 +127,41 @@ impl History { // Step 5 let serialized_data = StructuredCloneData::write(cx, data)?.move_to_arraybuffer(); - // TODO: Steps 6-7 Url Handling - // https://github.com/servo/servo/issues/19157 + let new_url: ServoUrl = match url { + // Step 6 + Some(urlstring) => { + let document_url = document.url(); + + // Step 6.1 + let new_url = match ServoUrl::parse_with_base(Some(&document_url), &urlstring.0) { + // Step 6.3 + Ok(parsed_url) => parsed_url, + // Step 6.2 + Err(_) => return Err(Error::Security), + }; + + // Step 6.4 + if new_url.scheme() != document_url.scheme() || + new_url.host() != document_url.host() || + new_url.port() != document_url.port() || + new_url.username() != document_url.username() || + new_url.password() != document_url.password() + { + return Err(Error::Security); + } + + // Step 6.5 + if new_url.origin() != document_url.origin() { + return Err(Error::Security); + } + + new_url + }, + // Step 7 + None => { + document.url() + } + }; // Step 8 let state_id = match push_or_replace { @@ -162,8 +196,8 @@ impl History { // TODO: Step 9 Update current entry to represent a GET request // https://github.com/servo/servo/issues/19156 - // TODO: Step 10 Set document's URL to new URL - // https://github.com/servo/servo/issues/19157 + // Step 10 + document.set_url(new_url); // Step 11 let global_scope = self.window.upcast::(); diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/008.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/008.html.ini deleted file mode 100644 index d02f10bf16ba..000000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/008.html.ini +++ /dev/null @@ -1,7 +0,0 @@ -[008.html] - [history.pushState URL resolving should be done relative to the document, not the script] - expected: FAIL - - [history.replaceState URL resolving should be done relative to the document, not the script] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/009.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/009.html.ini deleted file mode 100644 index 6c2ee1ac71c5..000000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/009.html.ini +++ /dev/null @@ -1,13 +0,0 @@ -[009.html] - [HTTP Referer should use the pushed state] - expected: FAIL - - [document.referrer should use the pushed state] - expected: FAIL - - [HTTP Referer should use the replaced state] - expected: FAIL - - [document.referrer should use the replaced state] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/010.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/010.html.ini deleted file mode 100644 index 27117024d9c7..000000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/010.html.ini +++ /dev/null @@ -1,13 +0,0 @@ -[010.html] - [HTTP Referer should use the pushed state (before onload)] - expected: FAIL - - [document.referrer should use the pushed state (before onload)] - expected: FAIL - - [HTTP Referer should use the replaced state (before onload)] - expected: FAIL - - [document.referrer should use the replaced state (before onload)] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/011.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/011.html.ini deleted file mode 100644 index 371120da5101..000000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/011.html.ini +++ /dev/null @@ -1,7 +0,0 @@ -[011.html] - [pushed location should be reflected immediately] - expected: FAIL - - [pushed location should be retained after the page has loaded] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/012.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/012.html.ini deleted file mode 100644 index 2169780fb92e..000000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/012.html.ini +++ /dev/null @@ -1,7 +0,0 @@ -[012.html] - [replaced location should be reflected immediately] - expected: FAIL - - [replaced location should be retained after the page has loaded] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_pushstate_err.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_pushstate_err.html.ini deleted file mode 100644 index 07540a9e8e0f..000000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_pushstate_err.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[history_pushstate_err.html] - [history pushState SECURITY_ERR] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_replacestate_err.html.ini b/tests/wpt/metadata/html/browsers/history/the-history-interface/history_replacestate_err.html.ini deleted file mode 100644 index 8ee22ab224e7..000000000000 --- a/tests/wpt/metadata/html/browsers/history/the-history-interface/history_replacestate_err.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[history_replacestate_err.html] - [history replaceState SECURITY_ERR] - expected: FAIL - diff --git a/tests/wpt/metadata/html/browsers/history/the-location-interface/location_hash.html.ini b/tests/wpt/metadata/html/browsers/history/the-location-interface/location_hash.html.ini index 2cf94f6e2e68..14fb78311f2e 100644 --- a/tests/wpt/metadata/html/browsers/history/the-location-interface/location_hash.html.ini +++ b/tests/wpt/metadata/html/browsers/history/the-location-interface/location_hash.html.ini @@ -1,8 +1,5 @@ [location_hash.html] type: testharness - [location hash] - expected: FAIL - [Setting location.hash on srcdoc iframe] expected: FAIL diff --git a/tests/wpt/metadata/html/browsers/history/the-location-interface/location_search.html.ini b/tests/wpt/metadata/html/browsers/history/the-location-interface/location_search.html.ini deleted file mode 100644 index fa2ec8514b8e..000000000000 --- a/tests/wpt/metadata/html/browsers/history/the-location-interface/location_search.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[location_search.html] - type: testharness - [location search] - expected: FAIL - diff --git a/tests/wpt/metadata/html/semantics/forms/attributes-common-to-form-controls/formAction_document_address.html.ini b/tests/wpt/metadata/html/semantics/forms/attributes-common-to-form-controls/formAction_document_address.html.ini deleted file mode 100644 index 20dcacd19695..000000000000 --- a/tests/wpt/metadata/html/semantics/forms/attributes-common-to-form-controls/formAction_document_address.html.ini +++ /dev/null @@ -1,8 +0,0 @@ -[formAction_document_address.html] - type: testharness - [Check if button.formAction is the document's new address when formaction content attribute is missing and pushState has been used] - expected: FAIL - - [Check if input.formAction is the document's new address when formaction content attribute is missing and pushState has been used] - expected: FAIL -