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.
This commit is contained in:
Anthony Ramine 2017-10-10 16:14:40 +02:00
parent 826352ab4c
commit 605c679fee
11 changed files with 75 additions and 47 deletions

View file

@ -4,6 +4,7 @@
use cssparser::RGBA;
use dom::attr::Attr;
use dom::bindings::codegen::Bindings::AttrBinding::AttrBinding::AttrMethods;
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{self, HTMLBodyElementMethods};
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::inheritance::Castable;
@ -73,7 +74,12 @@ impl HTMLBodyElementMethods for HTMLBodyElement {
make_legacy_color_setter!(SetText, "text");
// https://html.spec.whatwg.org/multipage/#dom-body-background
make_getter!(Background, "background");
fn Background(&self) -> DOMString {
self.upcast::<Element>()
.get_attribute(&ns!(), &local_name!("background"))
.map(|attr| attr.Value())
.unwrap_or_default()
}
// https://html.spec.whatwg.org/multipage/#dom-body-background
make_url_setter!(SetBackground, "background");
@ -154,7 +160,7 @@ impl VirtualMethods for HTMLBodyElement {
local_name!("bgcolor") |
local_name!("text") => AttrValue::from_legacy_color(value.into()),
local_name!("background") => {
AttrValue::from_url(document_from_node(self).url(), value.into())
AttrValue::from_url(document_from_node(self).base_url(), value.into())
},
_ => self.super_type().unwrap().parse_plain_attribute(name, value),
}