diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index 38091fcf19e..2b4830dccfc 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -3,11 +3,11 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ //! The `ByteString` struct. - use chrono::prelude::{Utc, Weekday}; use chrono::{Datelike, TimeZone}; use cssparser::CowRcStr; use html5ever::{LocalName, Namespace}; +use regex::Regex; use servo_atoms::Atom; use std::borrow::{Borrow, Cow, ToOwned}; use std::default::Default; @@ -337,11 +337,11 @@ impl DOMString { /// https://html.spec.whatwg.org/multipage/#valid-floating-point-number pub fn is_valid_floating_point_number_string(&self) -> bool { - // for the case that `parse_floating_point_number` cannot handle - if self.0.contains(" ") { - return false; + lazy_static! { + static ref RE: Regex = + Regex::new(r"^-?(?:\d+\.\d+|\d+|\.\d+)(?:(e|E)(\+|\-)?\d+)?$").unwrap(); } - parse_floating_point_number(&self.0).is_ok() + RE.is_match(&self.0) && parse_floating_point_number(&self.0).is_ok() } /// https://html.spec.whatwg.org/multipage/#best-representation-of-the-number-as-a-floating-point-number diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 5fdbad5c1bd..b48dfbc42db 100755 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -1213,7 +1213,16 @@ impl HTMLInputElement { value.push_str(sanitized.as_str()); } }, - _ => (), + // The following inputs don't have a value sanitization algorithm. + // See https://html.spec.whatwg.org/multipage/#value-sanitization-algorithm + InputType::Button | + InputType::Checkbox | + InputType::File | + InputType::Hidden | + InputType::Image | + InputType::Radio | + InputType::Reset | + InputType::Submit => (), } } diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index f874a593c60..89f1a3893da 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -659568,7 +659568,7 @@ "testharness" ], "html/semantics/forms/the-input-element/number.html": [ - "64868f02efca707cfe88a51e9bd91574dfbcaad9", + "7d93f208985d305d46324d0ecf34e8c4ff2ad361", "testharness" ], "html/semantics/forms/the-input-element/password.html": [ diff --git a/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/number.html b/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/number.html index 64868f02efc..7d93f208985 100644 --- a/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/number.html +++ b/tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/number.html @@ -35,7 +35,11 @@ {value: "+1", expected: "", testname: "value = +1"}, {value: "+", expected: "", testname: "value = '+'"}, {value: "-", expected: "", testname: "value = '-'"}, - {value: " 1", expected: "", testname: "value with a leading whitespace"}, + {value: "\t1", expected: "", testname: "value with a leading tab"}, + {value: "\n1", expected: "", testname: "value with a leading newline"}, + {value: "\f1", expected: "", testname: "value with a leading form feed"}, + {value: "\r1", expected: "", testname: "value with a leading carriage return"}, + {value: " 1", expected: "", testname: "value with a leading space"}, {value: "1trailing junk", expected: "", testname: "value = 1trailing junk"} ]; for (var i = 0; i < numbers.length; i++) {