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

@ -93,7 +93,7 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
make_setter!(SetType, "type");
// https://html.spec.whatwg.org/multipage/#dom-fs-formaction
make_url_or_base_getter!(FormAction, "formaction");
make_form_action_getter!(FormAction, "formaction");
// https://html.spec.whatwg.org/multipage/#dom-fs-formaction
make_setter!(SetFormAction, "formaction");

View file

@ -100,7 +100,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
make_setter!(SetAcceptCharset, "accept-charset");
// https://html.spec.whatwg.org/multipage/#dom-fs-action
make_string_or_document_url_getter!(Action, "action");
make_form_action_getter!(Action, "action");
// https://html.spec.whatwg.org/multipage/#dom-fs-action
make_setter!(SetAction, "action");

View file

@ -452,7 +452,7 @@ impl HTMLInputElementMethods for HTMLInputElement {
make_setter!(SetPlaceholder, "placeholder");
// https://html.spec.whatwg.org/multipage/#dom-input-formaction
make_url_or_base_getter!(FormAction, "formaction");
make_form_action_getter!(FormAction, "formaction");
// https://html.spec.whatwg.org/multipage/#dom-input-formaction
make_setter!(SetFormAction, "formaction");

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(),
}
}
);

View file

@ -1,5 +0,0 @@
[form-action-reflection-with-base-url.html]
type: testharness
[An action URL should be resolved relative to the document's base URL (not the document's URL)]
expected: FAIL

View file

@ -1,5 +0,0 @@
[form-action-reflection.html]
type: testharness
[An action URL should be resolved relative to the document's base URL (= the document's URL in this case)]
expected: FAIL