Fix the form action IDL attributes

The returned string, if the attribute is present and non-empty,
should be a URL resolved against the element's document's base URL.
This commit is contained in:
Anthony Ramine 2017-10-11 10:09:42 +02:00
parent 605c679fee
commit 71b015173f
6 changed files with 14 additions and 40 deletions

View file

@ -106,38 +106,22 @@ macro_rules! make_url_getter(
);
#[macro_export]
macro_rules! make_url_or_base_getter(
macro_rules! make_form_action_getter(
( $attr:ident, $htmlname:tt ) => (
fn $attr(&self) -> DOMString {
use dom::bindings::inheritance::Castable;
use dom::element::Element;
let element = self.upcast::<Element>();
let url = element.get_url_attribute(&local_name!($htmlname));
if url.is_empty() {
let window = window_from_node(self);
DOMString::from(window.get_url().into_string())
} else {
url
}
}
);
);
#[macro_export]
macro_rules! make_string_or_document_url_getter(
( $attr:ident, $htmlname:tt ) => (
fn $attr(&self) -> DOMString {
use dom::bindings::inheritance::Castable;
use dom::element::Element;
use dom::node::document_from_node;
let element = self.upcast::<Element>();
let val = element.get_string_attribute(&local_name!($htmlname));
if val.is_empty() {
let doc = document_from_node(self);
DOMString::from(doc.url().into_string())
} else {
val
let doc = ::dom::node::document_from_node(self);
let attr = element.get_attribute(&ns!(), &local_name!($htmlname));
let value = attr.as_ref().map(|attr| attr.value());
let value = match value {
Some(ref value) if !value.is_empty() => &***value,
_ => return doc.url().into_string().into(),
};
match doc.base_url().join(value) {
Ok(parsed) => parsed.into_string().into(),
Err(_) => value.to_owned().into(),
}
}
);