diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2017-10-10 16:14:40 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2017-10-11 13:56:07 +0200 |
commit | 605c679fee29302321878a74b88aa7165519b516 (patch) | |
tree | c52ffde5e21c61b3a5cbdc5aa308247741bb708d /components/script/dom/htmlbaseelement.rs | |
parent | 826352ab4cae13f5154d13ab53885d80a8057337 (diff) | |
download | servo-605c679fee29302321878a74b88aa7165519b516.tar.gz servo-605c679fee29302321878a74b88aa7165519b516.zip |
Fix URL attributes
URL attributes should always use AttrValue::Url, and the input should be
resolved against the document's base URL at setting time always.
Diffstat (limited to 'components/script/dom/htmlbaseelement.rs')
-rw-r--r-- | components/script/dom/htmlbaseelement.rs | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/components/script/dom/htmlbaseelement.rs b/components/script/dom/htmlbaseelement.rs index ada9539833a..c1c3c07aaf0 100644 --- a/components/script/dom/htmlbaseelement.rs +++ b/components/script/dom/htmlbaseelement.rs @@ -16,7 +16,6 @@ use dom::virtualmethods::VirtualMethods; use dom_struct::dom_struct; use html5ever::{LocalName, Prefix}; use servo_url::ServoUrl; -use style::attr::AttrValue; #[dom_struct] pub struct HTMLBaseElement { @@ -67,28 +66,31 @@ impl HTMLBaseElement { impl HTMLBaseElementMethods for HTMLBaseElement { // https://html.spec.whatwg.org/multipage/#dom-base-href fn Href(&self) -> DOMString { - let document = document_from_node(self); - // Step 1. - if !self.upcast::<Element>().has_attribute(&local_name!("href")) { - return DOMString::from(document.base_url().as_str()); - } + let document = document_from_node(self); // Step 2. - let fallback_base_url = document.fallback_base_url(); + let attr = self.upcast::<Element>().get_attribute(&ns!(), &local_name!("href")); + let value = attr.as_ref().map(|attr| attr.value()); + let url = value.as_ref().map_or("", |value| &**value); // Step 3. - let url = self.upcast::<Element>().get_url_attribute(&local_name!("href")); - - // Step 4. - let url_record = fallback_base_url.join(&*url); - - // Step 5, 6. - DOMString::from(url_record.as_ref().map(|url| url.as_str()).unwrap_or("")) + let url_record = document.fallback_base_url().join(url); + + match url_record { + Err(_) => { + // Step 4. + url.into() + } + Ok(url_record) => { + // Step 5. + url_record.into_string().into() + }, + } } // https://html.spec.whatwg.org/multipage/#dom-base-href - make_url_setter!(SetHref, "href"); + make_setter!(SetHref, "href"); } impl VirtualMethods for HTMLBaseElement { |