Skip to content

Implemented sanitize_value for time input - #19379

Merged
bors-servo merged 1 commit into
servo:masterfrom
SWW13:htmlinput_sanitize_time
Dec 4, 2017
Merged

bors-servo merged 1 commit into
servo:masterfrom
SWW13:htmlinput_sanitize_time

Conversation

@SWW13

@SWW13 SWW13 commented Nov 26, 2017 •

Copy link
Copy Markdown
Contributor

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.



This change is Reviewable

@KiChjang KiChjang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start! Could you move the validation methods to components/script/dom/bindings/str.rs and create a method called is_valid_time_string for DOMString instead?

let is_hour = |h: u8| h <= 23;
let is_minute = |m: u8| m <= 59;
let is_second = |s: u8| s <= 59;
let is_ms = |ms: u16| ms <= 999;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these closures necessary? Comparing the characters directly should be sufficient.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not necessary but I started with an version without parse and they made the code easy to read IMHO. The compiler should inline them anyway.

len >= 5 &&
// HH:mm
is_hour(content[0..2].parse().unwrap_or(99)) &&
is_colon(&content[2..3]) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a longer version of &content[2].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&content[2] used to return a char, but that was removed b/c it doesn't work as expected when dealing with utf8. It would be fine for use as the only valid content is ASCII, but that's an edge case we're hitting here.
Maybe working with the underlying byte slice would work, but that's a dirty solution IMHO.


len >= 5 &&
// HH:mm
is_hour(content[0..2].parse().unwrap_or(99)) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's necessary to parse the integer here (and below). We're simply trying to validate the string, not generate a numerical representation of it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revert to my early try, but the string validation is a bit of a mess b/c of the utf8 encoding of the strings in rust.

@KiChjang

Copy link
Copy Markdown
Contributor

It would also be great if you can link to the spec here and provide step annotations on your code, so that future readers of the code would not be too surprised by what's happening in the code.

@KiChjang KiChjang self-assigned this Nov 27, 2017
@SWW13
SWW13 force-pushed the htmlinput_sanitize_time branch from f50fa79 to 8448363 Compare November 27, 2017 12:06
@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 27, 2017
@SWW13
SWW13 force-pushed the htmlinput_sanitize_time branch 2 times, most recently from f1105c5 to 938b3f6 Compare November 27, 2017 12:18
@KiChjang

Copy link
Copy Markdown
Contributor

@bors-servo try

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Trying commit 938b3f6 with merge 52601a5...

bors-servo pushed a commit that referenced this pull request Nov 27, 2017
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
  - [ ] 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 -->
@KiChjang KiChjang added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Nov 27, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-rel-wpt3

@highfive highfive added the S-tests-failed The changes caused existing tests to fail. label Nov 27, 2017
@jdm

jdm commented Nov 27, 2017

Copy link
Copy Markdown
Member

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/time-2.html:
  └ PASS [expected FAIL] Invalid value: fraction should have one, two or three ASCII digits. Value should be empty

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/time-2.html:
  └ PASS [expected FAIL] Invalid value: hour should have two ASCII digits. Value should be empty

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/time-2.html:
  └ PASS [expected FAIL] Invalid value: minutes should have two ASCII digits. Value should be empty

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/time-2.html:
  └ PASS [expected FAIL] Invalid value: seconds should have two ASCII digits. Value should be empty

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/time-2.html:
  └ PASS [expected FAIL] Invalid value: hour > 23. Value should be empty

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/time-2.html:
  └ PASS [expected FAIL] Invalid value: minute > 59. Value should be empty

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/time-2.html:
  └ PASS [expected FAIL] Invalid value: second > 59. Value should be empty

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from hidden to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from text to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from search to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from tel to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from url to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from email to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from password to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from datetime-local to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from date to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from month to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from week to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from time to hidden

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from time to datetime-local

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from time to date

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from time to month

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from time to week

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from time to number

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from time to submit

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from time to image

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from time to reset

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from time to button

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from number to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from range to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from checkbox to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from radio to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from submit to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from image to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from reset to time

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  └ PASS [expected FAIL] change state from button to time

  ▶ 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

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/valueMode.html:
  └ PASS [expected FAIL] value IDL attribute of input type time without value attribute

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/valueMode.html:
  └ PASS [expected FAIL] value IDL attribute of input type time with value attribute

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/time.html:
  └ PASS [expected FAIL] set value on not time format value

@SWW13

SWW13 commented Nov 29, 2017

Copy link
Copy Markdown
Contributor Author

Are these test results expected or not?

@KiChjang

Copy link
Copy Markdown
Contributor

They were expected to fail, but after your changes, they now pass, which is a positive sign! All you need to do now is to update the test expectations and address my comments, and we can finally land this!

Comment thread components/script/dom/bindings/str.rs Outdated
// Step 2 ":"
is_colon(bytes[2]) &&
// Step 3 "mm"
is_minute(&bytes[3..5]) &&

@KiChjang KiChjang Nov 29, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't shake the feeling that the code as it is written is brittle. At the very least though, I can safely say that this isn't as maintainable as it can be, since there's a lot of index calculations based on the positions of the characters.

What particularly makes me nervous is when we're indexing the arrays directly in such a manner, because array indexing can panic during runtime, and if we're not careful enough to validate our assumptions, we would encounter a bug and the thread would panic.

If we can instead iterate through the characters and returning early when we encounter a wrong character, that would be safer and I would feel a bit more relaxed since the language itself would guarantee some invariants that we hold in our assumptions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any good idea how to avoid indexing without bloating the code?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose using Iterator::fold and keeping a state machine with the accumulator.

@SWW13
SWW13 force-pushed the htmlinput_sanitize_time branch from 938b3f6 to de954f9 Compare November 30, 2017 09:24
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-tests-failed The changes caused existing tests to fail. S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Nov 30, 2017
@SWW13

SWW13 commented Nov 30, 2017

Copy link
Copy Markdown
Contributor Author

New tests still work in progress.

@KiChjang KiChjang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good! I only have a couple of small comments.

}
let next_state = |valid: bool, next: State| -> State { if valid { next } else { State::Error } };

let state = self.chars().fold(State::HourHigh, |state, c| {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that we didn't check here is whether the character is ASCII. If at any point we run into a non-ASCII character, we would want to error out. In addition, I recall that iterating over chars is actually a bit slow, due to the fact that it needs to ensure UTF-8 well-formedness on each iteration.

So instead, maybe we could iterate over the underlying u8 data type by calling as_bytes, and importing AsciiExt so that we can use the .is_ascii() function to check whether the character is ASCII on each iteration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if Unicode has other digits that are valid for is_digit, if not we are already check for ASCII implicit.
When using bytes (u8) there should be no need to check for ASCII as we already check for specific values (0-9, :, .) which implies there are only ASCII values.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'll leave it up to you whether you want to use u8 or char in this PR.

}

// type[j] sanitization
if ((types[i].type !== "color" && types[j].sanitizedValue) || types[j].sanitizedValue === "") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for the color type is actually an incorrect change that I wrongly approved of. This should instead just check whether the sanitizedValue exists on the types object.

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 === "") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordering on this test looks wrong. If I'm reading correctly, j represents the destination input type that this input element is changing to, so the value sanitization algorithm should run for the input type described by types[j] first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure how to do this right. We have an input sanitization which may set the value to empty string, trims it somehow or replace it with a default value on source input type and then afterwards another that possibly do the same with that value on the destination input type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the part of the spec that specifies this behaviour is located here https://html.spec.whatwg.org/multipage/input.html#input-type-change, and in the code it's this line:

self.sanitize_value();

... which will get called whenever the value content attribute is modified.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're getting near the expected test behavior, the only thing left is:

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  │ FAIL [expected PASS] change state from time to checkbox
  │   → assert_equals: input.value should be '' after change of state expected "" but got "on"
  │ FAIL [expected PASS] change state from time to radio
  │   → assert_equals: input.value should be '' after change of state expected "" but got "on"

BTW: There are many tests that pass who should fail (many date / number related input type changes).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ick, this is because the default value for radio and checkbox is "on" instead of the empty string:

.map_or(DOMString::from("on"),

So, perhaps instead of having a default boolean field on the test object, we should have a defaultValue string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I try to find a nice solution the more I break :/ The additional defaultValue is ugly, but at least the tests work now.

if (types[i].type === "file") {
assert_throws("INVALID_STATE_ERR", function() {
input.value = " foo\rbar ";
input.value = expected;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why set input.value = expected; here?
I think keep expected = " foo\rbar " is fine.

@KiChjang KiChjang Nov 30, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine, it deduplicates the repeated construction of a new string.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving input.value = " foo\rbar " is good.
But input.value = expected; seems unnecessary.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following. This subtest in particular throws an exception when input.value is being assigned to. Are you saying that we should rather duplicate writing " foo\rbar " here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO, we have moved input.value = " foo\rbar " to the front of if section.
input.value is set, and not need to set input.value = expected;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've lost me. The change that this patch has is var expected = " foo\rbar "; instead of input.value = " foo\rbar ";

}
}

assert_equals(input.value, expected, "input.value should be '" + expected + "' after change of state");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KiChjang which mean this line is unnecessary to change to expected, just keep the origin " foo\rbar "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is clearly not the case, because the expected value may change depending on whether the destination type has a sanitizedValue as defined above in this test file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping " foo\rbar " is wrong, we are not always expecting " foo\rbar ", sometimes it's "#000000", "foo\rbar" or "".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Got your point.

@tigercosmos

Copy link
Copy Markdown
Contributor

Seems #19379 and #19385 overlap at type-change-state.html and self.sanitize_value();
Maybe I wait for this one? @KiChjang

@KiChjang

KiChjang commented Dec 1, 2017

Copy link
Copy Markdown
Contributor

@tigercosmos Not necessary, whichever PR lands last would simply need to rebase against master.

@SWW13
SWW13 force-pushed the htmlinput_sanitize_time branch from 0a83969 to a999239 Compare December 4, 2017 10:23
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Dec 4, 2017
@KiChjang

KiChjang commented Dec 4, 2017

Copy link
Copy Markdown
Contributor

@bors-servo r+

Thanks!

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit a999239 has been approved by KiChjang

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Dec 4, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit a999239 with merge 07192a1...

bors-servo pushed a commit that referenced this pull request Dec 4, 2017
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 -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-wpt

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Dec 4, 2017
@jdm

jdm commented Dec 4, 2017

Copy link
Copy Markdown
Member

@bors-servo: retry

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit a999239 with merge 8e7a079...

bors-servo pushed a commit that referenced this pull request Dec 4, 2017
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 -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Dec 4, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - linux-rel-css

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Dec 4, 2017
@jdm

jdm commented Dec 4, 2017

Copy link
Copy Markdown
Member

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit a999239 with merge eed3adc...

bors-servo pushed a commit that referenced this pull request Dec 4, 2017
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 -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Dec 4, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: KiChjang
Pushing eed3adc to master...

@bors-servo
bors-servo merged commit a999239 into servo:master Dec 4, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Dec 4, 2017
jdm pushed a commit to web-platform-tests/wpt that referenced this pull request Jan 4, 2018
- Implemented is_valid_time_string for DOMString.
- Use is_valid_time_string for sanitize_value with time input.
- Improved input type change test

Upstreamed from servo/servo#19379 [ci skip]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants