diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-05-24 07:42:23 -0700 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-05-24 07:42:23 -0700 |
commit | 8c4929a196ca933532d0c6948c9eebd92be4013a (patch) | |
tree | 4fcf03339f728040fdbbcc7ead9bdf5113e3269a | |
parent | cd1396fa9ae72bebf13115ed0d752fb21ce0df19 (diff) | |
parent | c93ed39f3366b8a3b889884b0bdab30c1fadbde1 (diff) | |
download | servo-8c4929a196ca933532d0c6948c9eebd92be4013a.tar.gz servo-8c4929a196ca933532d0c6948c9eebd92be4013a.zip |
Auto merge of #10962 - KiChjang:input-attr-parse, r=asajeffrey
Parse HTMLInputElement attributes
Fixes #10491.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10962)
<!-- Reviewable:end -->
-rw-r--r-- | components/script/dom/htmlinputelement.rs | 49 | ||||
-rw-r--r-- | components/style/attr.rs | 21 | ||||
-rw-r--r-- | components/util/str.rs | 4 | ||||
-rw-r--r-- | tests/wpt/metadata/html/dom/reflection-forms.html.ini | 102 |
4 files changed, 44 insertions, 132 deletions
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index dbc0d4f8f1f..8977d45048e 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -271,22 +271,22 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> { impl HTMLInputElementMethods for HTMLInputElement { - // https://html.spec.whatwg.org/multipage/#attr-input-accept + // https://html.spec.whatwg.org/multipage/#dom-input-accept make_getter!(Accept, "accept"); - // https://html.spec.whatwg.org/multipage/#attr-input-accept + // https://html.spec.whatwg.org/multipage/#dom-input-accept make_setter!(SetAccept, "accept"); - // https://html.spec.whatwg.org/multipage/#attr-input-alt + // https://html.spec.whatwg.org/multipage/#dom-input-alt make_getter!(Alt, "alt"); - // https://html.spec.whatwg.org/multipage/#attr-input-alt + // https://html.spec.whatwg.org/multipage/#dom-input-alt make_setter!(SetAlt, "alt"); - // https://html.spec.whatwg.org/multipage/#attr-input-dirName + // https://html.spec.whatwg.org/multipage/#dom-input-dirName make_getter!(DirName, "dirname"); - // https://html.spec.whatwg.org/multipage/#attr-input-dirName + // https://html.spec.whatwg.org/multipage/#dom-input-dirName make_setter!(SetDirName, "dirname"); // https://html.spec.whatwg.org/multipage/#dom-fe-disabled @@ -415,10 +415,10 @@ impl HTMLInputElementMethods for HTMLInputElement { // https://html.spec.whatwg.org/multipage/#attr-fe-name make_atomic_setter!(SetName, "name"); - // https://html.spec.whatwg.org/multipage/#attr-input-placeholder + // https://html.spec.whatwg.org/multipage/#dom-input-placeholder make_getter!(Placeholder, "placeholder"); - // https://html.spec.whatwg.org/multipage/#attr-input-placeholder + // https://html.spec.whatwg.org/multipage/#dom-input-placeholder make_setter!(SetPlaceholder, "placeholder"); // https://html.spec.whatwg.org/multipage/#dom-input-formaction @@ -454,10 +454,10 @@ impl HTMLInputElementMethods for HTMLInputElement { // https://html.spec.whatwg.org/multipage/#attr-fs-formnovalidate make_bool_setter!(SetFormNoValidate, "formnovalidate"); - // https://html.spec.whatwg.org/multipage/#attr-input-max + // https://html.spec.whatwg.org/multipage/#dom-input-max make_getter!(Max, "max"); - // https://html.spec.whatwg.org/multipage/#attr-input-max + // https://html.spec.whatwg.org/multipage/#dom-input-max make_setter!(SetMax, "max"); // https://html.spec.whatwg.org/multipage/#dom-input-maxlength @@ -466,40 +466,40 @@ impl HTMLInputElementMethods for HTMLInputElement { // https://html.spec.whatwg.org/multipage/#dom-input-maxlength make_limited_int_setter!(SetMaxLength, "maxlength", DEFAULT_MAX_LENGTH); - // https://html.spec.whatwg.org/multipage/#attr-input-min + // https://html.spec.whatwg.org/multipage/#dom-input-min make_getter!(Min, "min"); - // https://html.spec.whatwg.org/multipage/#attr-input-min + // https://html.spec.whatwg.org/multipage/#dom-input-min make_setter!(SetMin, "min"); - // https://html.spec.whatwg.org/multipage/#attr-input-multiple + // https://html.spec.whatwg.org/multipage/#dom-input-multiple make_bool_getter!(Multiple, "multiple"); - // https://html.spec.whatwg.org/multipage/#attr-input-multiple + // https://html.spec.whatwg.org/multipage/#dom-input-multiple make_bool_setter!(SetMultiple, "multiple"); - // https://html.spec.whatwg.org/multipage/#attr-input-pattern + // https://html.spec.whatwg.org/multipage/#dom-input-pattern make_getter!(Pattern, "pattern"); - // https://html.spec.whatwg.org/multipage/#attr-input-pattern + // https://html.spec.whatwg.org/multipage/#dom-input-pattern make_setter!(SetPattern, "pattern"); - // https://html.spec.whatwg.org/multipage/#attr-input-required + // https://html.spec.whatwg.org/multipage/#dom-input-required make_bool_getter!(Required, "required"); - // https://html.spec.whatwg.org/multipage/#attr-input-required + // https://html.spec.whatwg.org/multipage/#dom-input-required make_bool_setter!(SetRequired, "required"); - // https://html.spec.whatwg.org/multipage/#attr-input-src - make_getter!(Src, "src"); + // https://html.spec.whatwg.org/multipage/#dom-input-src + make_url_getter!(Src, "src"); - // https://html.spec.whatwg.org/multipage/#attr-input-src - make_setter!(SetSrc, "src"); + // https://html.spec.whatwg.org/multipage/#dom-input-src + make_url_setter!(SetSrc, "src"); - // https://html.spec.whatwg.org/multipage/#attr-input-step + // https://html.spec.whatwg.org/multipage/#dom-input-step make_getter!(Step, "step"); - // https://html.spec.whatwg.org/multipage/#attr-input-step + // https://html.spec.whatwg.org/multipage/#dom-input-step make_setter!(SetStep, "step"); // https://html.spec.whatwg.org/multipage/#dom-input-indeterminate @@ -881,6 +881,7 @@ impl VirtualMethods for HTMLInputElement { fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue { match name { + &atom!("accept") => AttrValue::from_comma_separated_tokenlist(value.into()), &atom!("name") => AttrValue::from_atomic(value.into()), &atom!("size") => AttrValue::from_limited_u32(value.into(), DEFAULT_INPUT_SIZE), &atom!("type") => AttrValue::from_atomic(value.into()), diff --git a/components/style/attr.rs b/components/style/attr.rs index 8bb307040ea..0ba247e101f 100644 --- a/components/style/attr.rs +++ b/components/style/attr.rs @@ -11,7 +11,7 @@ use std::str::FromStr; use string_cache::{Atom, Namespace}; use url::Url; use util::str::{LengthOrPercentageOrAuto, HTML_SPACE_CHARACTERS}; -use util::str::{read_exponent, read_fraction, read_numbers, split_html_space_chars}; +use util::str::{read_exponent, read_fraction, read_numbers, split_commas, split_html_space_chars}; use values::specified::{Length}; // Duplicated from script::dom::values. @@ -124,6 +124,15 @@ impl AttrValue { AttrValue::TokenList(tokens, atoms) } + pub fn from_comma_separated_tokenlist(tokens: String) -> AttrValue { + let atoms = split_commas(&tokens).map(Atom::from) + .fold(vec![], |mut acc, atom| { + if !acc.contains(&atom) { acc.push(atom) } + acc + }); + AttrValue::TokenList(tokens, atoms) + } + #[cfg(not(feature = "gecko"))] // Gecko can't borrow atoms as UTF-8. pub fn from_atomic_tokens(atoms: Vec<Atom>) -> AttrValue { use util::str::str_join; @@ -151,12 +160,12 @@ impl AttrValue { // https://html.spec.whatwg.org/multipage/#reflecting-content-attributes-in-idl-attributes:idl-double pub fn from_double(string: String, default: f64) -> AttrValue { let result = parse_double(&string).unwrap_or(default); - let result = if result.is_infinite() { - default + + if result.is_normal() { + AttrValue::Double(string, result) } else { - result - }; - AttrValue::Double(string, result) + AttrValue::Double(string, default) + } } // https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers diff --git a/components/util/str.rs b/components/util/str.rs index fe23c1b5ff6..7af63f4c7f3 100644 --- a/components/util/str.rs +++ b/components/util/str.rs @@ -41,6 +41,10 @@ pub fn split_html_space_chars<'a>(s: &'a str) -> s.split(HTML_SPACE_CHARACTERS).filter(not_empty as fn(&&str) -> bool) } +pub fn split_commas<'a>(s: &'a str) -> Filter<Split<'a, char>, fn(&&str) -> bool> { + fn not_empty(&split: &&str) -> bool { !split.is_empty() } + s.split(',').filter(not_empty as fn(&&str) -> bool) +} fn is_ascii_digit(c: &char) -> bool { match *c { diff --git a/tests/wpt/metadata/html/dom/reflection-forms.html.ini b/tests/wpt/metadata/html/dom/reflection-forms.html.ini index 84f4224e156..a41391a3f7f 100644 --- a/tests/wpt/metadata/html/dom/reflection-forms.html.ini +++ b/tests/wpt/metadata/html/dom/reflection-forms.html.ini @@ -4341,108 +4341,6 @@ [input.inputMode: IDL set to "URL" followed by IDL get] expected: FAIL - [input.src: setAttribute() to "" followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to " foo " followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to "//site.example/path???@#l" followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to "\\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f " followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to undefined followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to 7 followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to 1.5 followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to true followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to false followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to object "[object Object\]" followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to NaN followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to Infinity followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to -Infinity followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to "\\0" followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to null followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to object "test-toString" followed by IDL get] - expected: FAIL - - [input.src: setAttribute() to object "test-valueOf" followed by IDL get] - expected: FAIL - - [input.src: IDL set to "" followed by IDL get] - expected: FAIL - - [input.src: IDL set to " foo " followed by IDL get] - expected: FAIL - - [input.src: IDL set to "//site.example/path???@#l" followed by IDL get] - expected: FAIL - - [input.src: IDL set to "\\0\\x01\\x02\\x03\\x04\\x05\\x06\\x07 \\b\\t\\n\\v\\f\\r\\x0e\\x0f \\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17 \\x18\\x19\\x1a\\x1b\\x1c\\x1d\\x1e\\x1f " followed by IDL get] - expected: FAIL - - [input.src: IDL set to undefined followed by IDL get] - expected: FAIL - - [input.src: IDL set to 7 followed by IDL get] - expected: FAIL - - [input.src: IDL set to 1.5 followed by IDL get] - expected: FAIL - - [input.src: IDL set to true followed by IDL get] - expected: FAIL - - [input.src: IDL set to false followed by IDL get] - expected: FAIL - - [input.src: IDL set to object "[object Object\]" followed by IDL get] - expected: FAIL - - [input.src: IDL set to NaN followed by IDL get] - expected: FAIL - - [input.src: IDL set to Infinity followed by IDL get] - expected: FAIL - - [input.src: IDL set to -Infinity followed by IDL get] - expected: FAIL - - [input.src: IDL set to "\\0" followed by IDL get] - expected: FAIL - - [input.src: IDL set to null followed by IDL get] - expected: FAIL - - [input.src: IDL set to object "test-toString" followed by IDL get] - expected: FAIL - - [input.src: IDL set to object "test-valueOf" followed by IDL get] - expected: FAIL - [input.align: typeof IDL attribute] expected: FAIL |