Auto merge of #19379 - SWW13:htmlinput_sanitize_time, r=KiChjang

Implemented sanitize_value for time input

Implemented value sanitization for `<input type=time/>`.
The value has the be valid time string (https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-time-string) or set to empty string.

---

The following test results look expected to me, but I'm not sure:
```
  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  │ FAIL [expected PASS] change state from time to text
  │   → assert_equals: input.value should be   foobar   after change of state expected "  foobar  " but got ""
  │ FAIL [expected PASS] change state from time to search
  │   → assert_equals: input.value should be   foobar   after change of state expected "  foobar  " but got ""
  │ FAIL [expected PASS] change state from time to tel
  │   → assert_equals: input.value should be   foobar   after change of state expected "  foobar  " but got ""
  │ FAIL [expected PASS] change state from time to url
  │   → assert_equals: input.value should be foobar after change of state expected "foobar" but got ""
  │ FAIL [expected PASS] change state from time to password
  │   → assert_equals: input.value should be   foobar   after change of state expected "  foobar  " but got ""
  │
  │ @http://web-platform.test:8000/html/semantics/forms/the-input-element/type-change-state.html:53:15
  │ Test.prototype.step@http://web-platform.test:8000/resources/testharness.js:1489:20
  │ test@http://web-platform.test:8000/resources/testharness.js:511:9
  └ @http://web-platform.test:8000/html/semantics/forms/the-input-element/type-change-state.html:37:9

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  │ FAIL [expected PASS] change state from color to time
  │   → assert_equals: input.value should be #000000 after change of state expected "#000000" but got ""
  │
  │ @http://web-platform.test:8000/html/semantics/forms/the-input-element/type-change-state.html:55:15
  │ Test.prototype.step@http://web-platform.test:8000/resources/testharness.js:1489:20
  │ test@http://web-platform.test:8000/resources/testharness.js:511:9
  └ @http://web-platform.test:8000/html/semantics/forms/the-input-element/type-change-state.html:37:9
```

All other tests do now `PASS` instead of `FAIL`.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix *part of* #19172
- [x] There are tests for these changes
  - [x] All tests `PASS`

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19379)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-12-04 15:44:58 -06:00 committed by GitHub
commit eed3adc957
8 changed files with 228 additions and 157 deletions

View file

@ -15,16 +15,16 @@
{ type: "url", sanitizedValue: "foobar" },
{ type: "email", sanitizedValue: "foobar" },
{ type: "password", sanitizedValue: " foobar " },
{ type: "datetime-local", sanitizedValue: "" },
{ type: "date", sanitizedValue: "" },
{ type: "month", sanitizedValue: "" },
{ type: "week", sanitizedValue: "" },
{ type: "time", sanitizedValue: "" },
{ type: "number", sanitizedValue: "" },
{ type: "range", sanitizedValue: "50" },
{ type: "color", sanitizedValue: "#000000" },
{ type: "checkbox" },
{ type: "radio" },
{ type: "datetime-local", sanitizedValue: "", overridesSanitization: true },
{ type: "date", sanitizedValue: "", overridesSanitization: true },
{ type: "month", sanitizedValue: "", overridesSanitization: true },
{ type: "week", sanitizedValue: "", overridesSanitization: true },
{ type: "time", sanitizedValue: "", overridesSanitization: true },
{ type: "number", sanitizedValue: "", overridesSanitization: true },
{ type: "range", sanitizedValue: "50", overridesSanitization: true },
{ type: "color", sanitizedValue: "#000000", overridesSanitization: true },
{ type: "checkbox", defaultValue: "on" },
{ type: "radio", defaultValue: "on" },
{ type: "file" },
{ type: "submit" },
{ type: "image" },
@ -36,26 +36,39 @@
if (types[i] != types[j]) {
test(function() {
var input = document.createElement("input");
var expected = " foo\rbar ";
input.type = types[i].type;
if (types[i].type === "file") {
assert_throws("INVALID_STATE_ERR", function() {
input.value = " foo\rbar ";
input.value = expected;
});
assert_equals(input.value, "");
} else if (types[j].type === "file") {
input.value = " foo\rbar ";
input.value = expected;
input.type = types[j].type; // change state
assert_equals(input.value, "");
} else {
input.value = " foo\rbar ";
input.value = expected;
input.type = types[j].type; // change state
if (types[i].type !== "color" && (types[j].sanitizedValue || types[j].sanitizedValue === "")) {
assert_equals(input.value, types[j].sanitizedValue, "input.value should be " + types[j].sanitizedValue + " after change of state");
} else if (types[i].sanitizedValue || types[i].sanitizedValue === "") {
assert_equals(input.value, types[i].sanitizedValue, "input.value should be " + types[i].sanitizedValue + " after change of state");
} else {
assert_equals(input.value, " foo\rbar ", "input.value should be ' foo\\rbar ' after change of state");
// type[i] sanitization
if (types[i].sanitizedValue || types[i].sanitizedValue === "") {
expected = types[i].sanitizedValue;
}
// type[j] sanitization
if (types[j].sanitizedValue || types[j].sanitizedValue === "") {
if ((expected !== "" && !types[i].overridesSanitization) || types[j].overridesSanitization) {
expected = types[j].sanitizedValue;
}
}
// type[j] defaultValue
if (expected === "" && types[j].defaultValue) {
expected = types[j].defaultValue;
}
assert_equals(input.value, expected, "input.value should be '" + expected + "' after change of state");
}
}, "change state from " + types[i].type + " to " + types[j].type);
}