diff options
-rw-r--r-- | components/script/dom/document.rs | 8 | ||||
-rw-r--r-- | components/script/script_task.rs | 27 | ||||
-rw-r--r-- | tests/html/test_navigate.html | 2 | ||||
-rw-r--r-- | tests/html/test_navigate2.html | 2 |
4 files changed, 26 insertions, 13 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index c538893506b..bc1198afac3 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -256,7 +256,7 @@ pub trait DocumentHelpers<'a> { fn disarm_reflow_timeout(self); fn unregister_named_element(self, to_unregister: &Element, id: Atom); fn register_named_element(self, element: &Element, id: Atom); - fn find_fragment_node(self, fragid: DOMString) -> Option<Root<Element>>; + fn find_fragment_node(self, fragid: &str) -> Option<Root<Element>>; fn hit_test(self, point: &Point2D<f32>) -> Option<UntrustedNodeAddress>; fn get_nodes_under_mouse(self, point: &Point2D<f32>) -> Vec<UntrustedNodeAddress>; fn set_ready_state(self, state: DocumentReadyState); @@ -513,12 +513,12 @@ impl<'a> DocumentHelpers<'a> for &'a Document { /// Attempt to find a named element in this page's document. /// https://html.spec.whatwg.org/multipage/#the-indicated-part-of-the-document - fn find_fragment_node(self, fragid: DOMString) -> Option<Root<Element>> { - self.GetElementById(fragid.clone()).or_else(|| { + fn find_fragment_node(self, fragid: &str) -> Option<Root<Element>> { + self.GetElementById(fragid.to_owned()).or_else(|| { let check_anchor = |&node: &&HTMLAnchorElement| { let elem = ElementCast::from_ref(node); elem.get_attribute(&ns!(""), &atom!("name")).map_or(false, |attr| { - &**attr.r().value() == &*fragid + &**attr.r().value() == fragid }) }; let doc_node = NodeCast::from_ref(self); diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 8d342a9eaf5..438efaed0b1 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -82,6 +82,7 @@ use util::opts; use euclid::Rect; use euclid::point::Point2D; use hyper::header::{LastModified, Headers}; +use hyper::method::Method; use ipc_channel::ipc::{self, IpcSender}; use ipc_channel::router::ROUTER; use js::glue::CollectServoSizes; @@ -1727,16 +1728,24 @@ impl ScriptTask { /// for the given pipeline (specifically the "navigate" algorithm). fn handle_navigate(&self, pipeline_id: PipelineId, subpage_id: Option<SubpageId>, load_data: LoadData) { // Step 8. - if let Some(fragment) = load_data.url.fragment { - let page = get_page(&self.root_page(), pipeline_id); - let document = page.document(); - match document.r().find_fragment_node(fragment) { - Some(ref node) => { - self.scroll_fragment_point(pipeline_id, node.r()); + { + let nurl = &load_data.url; + if let Some(ref fragment) = nurl.fragment { + let page = get_page(&self.root_page(), pipeline_id); + let document = page.document(); + let document = document.r(); + let url = document.url(); + if url.scheme == nurl.scheme && url.scheme_data == nurl.scheme_data && + url.query == nurl.query && load_data.method == Method::Get { + match document.find_fragment_node(&*fragment) { + Some(ref node) => { + self.scroll_fragment_point(pipeline_id, node.r()); + } + None => {} + } + return; } - None => {} } - return; } match subpage_id { @@ -1767,7 +1776,7 @@ impl ScriptTask { let document = page.document(); let fragment_node = window.r().steal_fragment_name() - .and_then(|name| document.r().find_fragment_node(name)); + .and_then(|name| document.r().find_fragment_node(&*name)); match fragment_node { Some(ref node) => self.scroll_fragment_point(pipeline_id, node.r()), None => {} diff --git a/tests/html/test_navigate.html b/tests/html/test_navigate.html new file mode 100644 index 00000000000..4e1119999d4 --- /dev/null +++ b/tests/html/test_navigate.html @@ -0,0 +1,2 @@ +<h1>This should change when the link is clicked</h1> +<a href="test_navigate2.html#t">Test link</a> <div id="t">Move</div> diff --git a/tests/html/test_navigate2.html b/tests/html/test_navigate2.html new file mode 100644 index 00000000000..f947c63a54c --- /dev/null +++ b/tests/html/test_navigate2.html @@ -0,0 +1,2 @@ +<h1>This should not change when the link is clicked</h1> +<a href="test_navigate2.html#t">Test link</a> <div id="t">Move</div> |