-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1839572 - Fix number input value sanitization. r=dom-core,edgar, …
…a=dsmith Differential Revision: https://phabricator.services.mozilla.com/D183055
- Loading branch information
1 parent
3581fd9
commit e7c28b8
Showing
2 changed files
with
54 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...b-platform/tests/html/semantics/forms/the-input-element/number-constraint-validation.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Form input type=number constraint validation</title> | ||
<link rel="author" title="Adam Vandolder" href="mailto:[email protected]"> | ||
<link rel=help href="https://html.spec.whatwg.org/multipage/#number-state-(type=number)"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<div id="log"></div> | ||
<input type="number"> | ||
<script> | ||
const input = document.querySelector("input"); | ||
const invalidInputNumber = "1.e"; | ||
const invalidSetNumber = "1."; | ||
|
||
promise_test(async () => { | ||
await test_driver.click(input); | ||
await test_driver.send_keys(input, invalidInputNumber); | ||
assert_equals(input.value.length, 0); | ||
assert_true(input.validity.badInput); | ||
}, "Unparsable number user input triggers sanitization and causes badInput to be set."); | ||
|
||
promise_test(async () => { | ||
input.value = invalidInputNumber; | ||
assert_equals(input.value.length, 0); | ||
assert_false(input.validity.badInput); | ||
}, "Setting .value to an unparsable number triggers sanitization but doesn't set badInput."); | ||
|
||
promise_test(async () => { | ||
await test_driver.click(input); | ||
await test_driver.send_keys(input, invalidSetNumber); | ||
assert_equals(input.value, "1"); | ||
assert_false(input.validity.badInput); | ||
}, "Users inputting a parsable but invalid floating point number doesn't trigger sanitization and doesn't set badInput."); | ||
|
||
promise_test(async () => { | ||
input.value = invalidSetNumber; | ||
assert_equals(input.value.length, 0); | ||
assert_false(input.validity.badInput); | ||
}, "Setting .value to a parsable but invalid floating point number triggers sanitization but doesn't set badInput."); | ||
</script> |