Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

number input type validations #19730

Merged
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

input type=number validations

  • Loading branch information
Nathan
Nathan committed Jan 10, 2018
commit 5b6e8215591c835dfb7092af25676d8ced344ebe
@@ -303,6 +303,16 @@ impl DOMString {
parse_week_string(&*self.0).is_ok()
}

/// A valid number is the same as what rust considers to be valid,
/// except for +1., NaN, and Infinity.
/// https://html.spec.whatwg.org/multipage/#valid-floating-point-number
pub fn is_valid_number_string(&self) -> bool {
let input = &self.0;
input.parse::<f64>().ok().map_or(false, |val| {
!(val.is_infinite() || val.is_nan() || input.ends_with(".") || input.starts_with("+"))
})
}

/// A valid normalized local date and time string should be "{date}T{time}"
/// where date and time are both valid, and the time string must be as short as possible
/// https://html.spec.whatwg.org/multipage/#valid-normalised-local-date-and-time-string
@@ -1045,6 +1045,12 @@ impl HTMLInputElement {
textinput.single_line_content_mut().clear();
}
}
InputType::Number => {
let mut textinput = self.textinput.borrow_mut();
if !textinput.single_line_content().is_valid_number_string() {
textinput.single_line_content_mut().clear();
}
}
// TODO: Implement more value sanitization algorithms for different types of inputs
_ => ()
}

This file was deleted.

@@ -6,9 +6,6 @@
[change state from hidden to datetime]
expected: FAIL

[change state from hidden to number]
expected: FAIL

[change state from hidden to range]
expected: FAIL

@@ -18,9 +15,6 @@
[change state from text to datetime]
expected: FAIL

[change state from text to number]
expected: FAIL

[change state from text to range]
expected: FAIL

@@ -30,9 +24,6 @@
[change state from search to datetime]
expected: FAIL

[change state from search to number]
expected: FAIL

[change state from search to range]
expected: FAIL

@@ -42,9 +33,6 @@
[change state from tel to datetime]
expected: FAIL

[change state from tel to number]
expected: FAIL

[change state from tel to range]
expected: FAIL

@@ -63,9 +51,6 @@
[change state from url to datetime]
expected: FAIL

[change state from url to number]
expected: FAIL

[change state from url to range]
expected: FAIL

@@ -93,9 +78,6 @@
[change state from email to datetime]
expected: FAIL

[change state from email to number]
expected: FAIL

[change state from email to range]
expected: FAIL

@@ -105,9 +87,6 @@
[change state from password to datetime]
expected: FAIL

[change state from password to number]
expected: FAIL

[change state from password to range]
expected: FAIL

@@ -132,9 +111,6 @@
[change state from datetime to week]
expected: FAIL

[change state from datetime to number]
expected: FAIL

[change state from datetime to range]
expected: FAIL

@@ -162,33 +138,6 @@
[change state from time to range]
expected: FAIL

[change state from number to hidden]
expected: FAIL

[change state from number to checkbox]
expected: FAIL

[change state from number to radio]
expected: FAIL

[change state from number to submit]
expected: FAIL

[change state from number to image]
expected: FAIL

[change state from number to reset]
expected: FAIL

[change state from number to button]
expected: FAIL

[change state from number to email]
expected: FAIL

[change state from number to datetime]
expected: FAIL

[change state from number to range]
expected: FAIL

@@ -219,15 +168,9 @@
[change state from range to datetime]
expected: FAIL

[change state from range to number]
expected: FAIL

[change state from checkbox to email]
expected: FAIL

[change state from checkbox to number]
expected: FAIL

[change state from checkbox to range]
expected: FAIL

@@ -237,9 +180,6 @@
[change state from radio to datetime]
expected: FAIL

[change state from radio to number]
expected: FAIL

[change state from radio to range]
expected: FAIL

@@ -249,9 +189,6 @@
[change state from submit to datetime]
expected: FAIL

[change state from submit to number]
expected: FAIL

[change state from submit to range]
expected: FAIL

@@ -261,9 +198,6 @@
[change state from image to datetime]
expected: FAIL

[change state from image to number]
expected: FAIL

[change state from image to range]
expected: FAIL

@@ -273,9 +207,6 @@
[change state from reset to datetime]
expected: FAIL

[change state from reset to number]
expected: FAIL

[change state from reset to range]
expected: FAIL

@@ -285,30 +216,12 @@
[change state from button to datetime]
expected: FAIL

[change state from button to number]
expected: FAIL

[change state from button to range]
expected: FAIL

[change state from datetime-local to range]
expected: FAIL

[change state from number to text]
expected: FAIL

[change state from number to search]
expected: FAIL

[change state from number to tel]
expected: FAIL

[change state from number to url]
expected: FAIL

[change state from number to password]
expected: FAIL

[change state from range to text]
expected: FAIL

@@ -324,9 +237,6 @@
[change state from range to password]
expected: FAIL

[change state from color to number]
expected: FAIL

[change state from color to range]
expected: FAIL

@@ -6,12 +6,6 @@
[value IDL attribute of input type datetime with value attribute]
expected: FAIL

[value IDL attribute of input type number without value attribute]
expected: FAIL

[value IDL attribute of input type number with value attribute]
expected: FAIL

[value IDL attribute of input type range without value attribute]
expected: FAIL

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.