diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-04-19 12:29:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-19 12:29:44 -0400 |
commit | 3c5f0a85debcb2fc7417137e2ea3a991fb6c5549 (patch) | |
tree | d2f371739b9c3c6bccfeab980b0e45fa53a4a303 /components/script/dom | |
parent | 3695fc4efc5a463175b301c71f3a3a7fe3b5c5a9 (diff) | |
parent | 68c4791c7d5ff71e60ab0edf966e9888a945b1a3 (diff) | |
download | servo-3c5f0a85debcb2fc7417137e2ea3a991fb6c5549.tar.gz servo-3c5f0a85debcb2fc7417137e2ea3a991fb6c5549.zip |
Auto merge of #20453 - talklittle:issue-19157, r=cbrewster
History: update document URL on pushState/replaceState
<!-- Please describe your changes on the following line: -->
Update Document URL when calling pushState and replaceState on History.
https://html.spec.whatwg.org/multipage/#dom-history-pushstate
Steps 6, 7, 10
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #19157 (github issue number if applicable).
<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20453)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/history.rs | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/components/script/dom/history.rs b/components/script/dom/history.rs index b158a9d44fd..a4ba5886373 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<USVString>, + url: Option<USVString>, 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::<GlobalScope>(); |