Skip to content

implement "Date type inputs", "Month type inputs" - #19385

Merged
bors-servo merged 1 commit into
servo:masterfrom
tigercosmos:b1
Dec 5, 2017
Merged

bors-servo merged 1 commit into
servo:masterfrom
tigercosmos:b1

Conversation

@tigercosmos

@tigercosmos tigercosmos commented Nov 26, 2017 •

Copy link
Copy Markdown
Contributor

implement "Date type inputs", "Month type inputs"


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • ./mach test-unit does not report any errors

This change is Reviewable

@highfive

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Nov 26, 2017

@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.

Sorry to do this to you, but I've come to believe that this code should instead be implemented on DOMString, defined in components/script/dom/bindings/str.rs, so that we can just write domstring.is_valid_date_string().

Also, I see that sanitize_value in htmlinputelement.rs is not being updated to use your code, would you mind updating that so it accurately sanitizes input values?

Comment thread components/style/attr.rs Outdated
let month = value_vec[1];
let day = value_vec[2];

// setp 1

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.

Step 1.

Comment thread components/style/attr.rs Outdated
return true;
}

/// Valid month string should be "YYYY-MM"

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 does not look correct, since step 1 clearly says that the year string can be 4 digits or more.

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.

um.. how about use

Valid month string should be "YYYY-MM",  YYYY must be four or more

Comment thread components/style/attr.rs Outdated
pub fn is_valid_month_string(value: &str) -> bool {
// step 2
let value_vec: Vec<&str> = value.split('-').collect();
if !(value_vec.len() == 2) {

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.

value_vec.len() != 2 and drop the parentheses.

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.

ok

Comment thread components/style/attr.rs Outdated
let year = value_vec[0];
let month = value_vec[1];

// setp 1

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.

Step 1.

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 get point here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think @KiChjang means there's a typo and have the comment with first character capitalized.

Comment thread components/style/attr.rs Outdated
// setp 1
if !(year.len() >= 4 &&
year.chars().all(|c| c.is_digit(10)) &&
year.parse::<i32>().unwrap() > 0) {

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 it in order to see whether the resulting i32 is larger than 0.

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.

yes, we only need to prevent the case "0000".
In this case, not parse to int is fine.

Comment thread components/style/attr.rs Outdated
}

// step 3
let month_int = month.parse::<i32>().unwrap();

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 can panic if the month string is not convertible to i32. I also think it's not necessary to parse the month 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.

I have checked if the string is 0~9 previously.
change to int will let the code clear.
We also can use, such as

month[0] == '1' && month[1]== '0'

but I think this is hard code

Comment thread components/style/attr.rs Outdated
let day = value_vec[2];

// setp 1
let month_string = format!("{}-{}", year, month);

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 pretty awkward, we've just split the string on -, but here we're heap-allocating a String with a - to parse a month 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.

YYYY-MM-DD

I want to get YYYY-MM. I don't know how to write it prettier.

Comment thread components/style/attr.rs Outdated

// setp 1
let month_string = format!("{}-{}", year, month);
if !is_valid_month_string(&*month_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.

If it helps to split the responsibilities between is_valid_month_string and is_valid_date_string more cleanly, we can instead implement parse a month component, and have that algorithm return a Result<(u32, u32), ParseError>.

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.

Ah. I think this is a good way.

Comment thread components/style/attr.rs Outdated
}
match month_int {
1|3|5|7|8|10|12 => {
if day_int > 31 {

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.

Let's instead extract the number of days in month of year into its own function, and have it return a u32 representing maxday.

@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
@tigercosmos

Copy link
Copy Markdown
Contributor Author

Sorry to do this to you, but I've come to believe that this code should instead be implemented on DOMString, defined in components/script/dom/bindings/str.rs, so that we can just write domstring.is_valid_date_string().
Also, I see that sanitize_value in htmlinputelement.rs is not being updated to use your code, would you mind updating that so it accurately sanitizes input values?

@KiChjang Change to there is OK, but you said in #19172

The valid date strings algorithm is what you will need to implement, and I think the appropriate place to put that algorithm would be in components/style/attr.rs.

How do you think? I can put where you think better.

Update htmlinputelement.rs will be the next step.

@KiChjang

Copy link
Copy Markdown
Contributor

Yeah sorry, forget about what I said in the original issue, that doesn't look like it's a good place to put the validation logic.

@tigercosmos

tigercosmos commented Nov 27, 2017 •

Copy link
Copy Markdown
Contributor Author

@KiChjang Where should I put the unit test at?
components/script/dom/bindings/str.rs have no match test folder.
Since /tests/unit/script has no sub-folder

@KiChjang

Copy link
Copy Markdown
Contributor

I think a WPT test would suffice for this; in fact, the tests under tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/month.html already tests for month strings. If you don't find them to be adequate, you're welcome (and encouraged!) to add additional tests under that file. Do realize that these tests are shared across different browsers, and it's a great way to test the web forward!

@tigercosmos tigercosmos changed the title implement "valid date string" and "valid month string" [WIP] implement "Date type inputs", "Month type inputs", "valid date string" and "valid month string" Nov 27, 2017
@tigercosmos

tigercosmos commented Nov 29, 2017 •

Copy link
Copy Markdown
Contributor Author

@KiChjang I got a problem
even I set

            atom!("month") => {
                let mut textinput = self.textinput.borrow_mut();
                textinput.set_content("".into());
            }

It will still return the origin value, like

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/month.html:
  │ FAIL [expected PASS] Month should be > 0: If the value of the element is not a valid month string, then set it to the empty string instead.>
  │   → assert_equals: expected "" but got "2013-00"
  │ 
  │ @http://web-platform.test:8000/html/semantics/forms/the-input-element/month.html:64:9
  │ 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/month.html:63:7

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/month.html:
  │ FAIL [expected PASS] Month should be <= 13: If the value of the element is not a valid month string, then set it to the empty string instead.
  │   → assert_equals: expected "" but got "2013-13"
  │ 
  │ @http://web-platform.test:8000/html/semantics/forms/the-input-element/month.html:60:9
  │ 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/month.html:59:7

@KiChjang

Copy link
Copy Markdown
Contributor

Can you push your code to this branch? It's hard to debug without any context.

@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 Nov 29, 2017
}
atom!("month") => {
let mut textinput = self.textinput.borrow_mut();
if ! textinput.single_line_content_mut().is_valid_month_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.

@KiChjang
even I set

            atom!("month") => {
                let mut textinput = self.textinput.borrow_mut();
                textinput.set_content("".into());
            }

It will still return the origin value, like

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/month.html:
  │ FAIL [expected PASS] Month should be > 0: If the value of the element is not a valid month string, then set it to the empty string instead.>
  │   → assert_equals: expected "" but got "2013-00"
  │ 
  │ @http://web-platform.test:8000/html/semantics/forms/the-input-element/month.html:64:9
  │ 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/month.html:63:7

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/month.html:
  │ FAIL [expected PASS] Month should be <= 13: If the value of the element is not a valid month string, then set it to the empty string instead.
  │   → assert_equals: expected "" but got "2013-13"
  │ 
  │ @http://web-platform.test:8000/html/semantics/forms/the-input-element/month.html:60:9
  │ 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/month.html:59:7

@CYBAI CYBAI Nov 29, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I just saw there's a space between ! and textinput.
Not sure if it will be an issue in Rust?

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, my guess here is that the value content attribute is not properly sanitized when it is first parsed. In other words, bind_to_tree needs to call sanitize_value.

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.

@CYBAI Although this is not proper style, there's no problem with adding a whitespace in-between ! and the expression that it is trying to negate, see https://play.rust-lang.org/?gist=d27e1e8f115cb01c70bf97b8c5312c60&version=stable.

@tigercosmos tigercosmos Nov 29, 2017 •

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.

@KiChjang I just follow color method(same code textinput.set_content("".into());), and seems color implement is correct (It passes tests). So..?

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.

@KiChjang You are right. Initialization works.
But I am wondering why color is fine lol

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.

Many other tests pass when I set initialization!

[[month\] stepUp method support on input 'month' element]
expected: FAIL

[[month\] The value must be a value that is a valid global date and time 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.

This is caused by time

@@ -1,8 +0,0 @@
[url.html]

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.

fix by initialization

@@ -1,11 +0,0 @@
[telephone.html]

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.

fix by initialization

if let Some(ref s) = self.super_type() {
s.bind_to_tree(tree_in_doc);
}

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.

Fix other test and this PR as well

@tigercosmos

Copy link
Copy Markdown
Contributor Author

I also believe these two are wrong test.
color to date will let the value to be "" not #000000

▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  │ FAIL [expected PASS] change state from color to date
  │   → assert_equals: input.value should be "#000000" after change of state expected "#000000" but got ""
  │ FAIL [expected PASS] change state from color to month
  │   → 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

@tigercosmos

Copy link
Copy Markdown
Contributor Author

@tigercosmos

Copy link
Copy Markdown
Contributor Author

r? @KiChjang

@tigercosmos tigercosmos changed the title [WIP] implement "Date type inputs", "Month type inputs", "valid date string" and "valid month string" implement "Date type inputs", "Month type inputs", "valid date string" and "valid month string" Nov 29, 2017
Comment thread components/script/dom/bindings/str.rs Outdated
let day = value_vec[2];

// Step 1
let month_string = format!("{}-{}", year, month);

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 still not OK. format! heap-allocates a String, and I believe we don't need any heap allocation at all.

Comment thread components/script/dom/bindings/str.rs Outdated
}
let year_int = year.parse::<i32>().unwrap();
let month_int = month.parse::<i32>().unwrap();
let day_int = day.parse::<i32>().unwrap();

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.

Sorry if I wasn't clear on my last request, but what I mean is that check_valid_month_string should instead be parse_month_string, which returns a type of Result<(u32, u32), ()> that contains a 2-tuple of a year-month pair for the success variant, and just an empty error for the other variant. That way, you don't need to parse here.

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.

@KiChjang
There is still year need to parse:

let year_int = year.parse::<i32>().unwrap();

If we parse the three(year, month, day) together would let the code more clear?

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 a code duplication that I would like to avoid, since you should have already parsed the month and year in the parse_month_string algorithm.

Comment thread components/script/dom/bindings/str.rs Outdated
} else if day_int > self.max_day_in_month(year_int, month_int) {
return false;
}
return true;

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.

nit: No explicit returns are necessary for the last expression.

Comment thread components/script/dom/bindings/str.rs Outdated

/// Valid month string should be "YYYY-MM"
/// https://html.spec.whatwg.org/multipage/#valid-month-string
pub fn is_valid_month_string(&mut self) -> bool {

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.

What's the purpose for this function? It looks to me as an unnecessary indirection.

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.

@KiChjang
because the origin usage is:

DOMString.is_valid_month_string()

The logic in it can be use in is_valid_date_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.

So perhaps my question is better phrased as "why is is_valid_month_string and check_valid_month_string" not the same function?

@tigercosmos tigercosmos Nov 30, 2017 •

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.

@KiChjang
when we call is_valid_month_string will deal the self.0 string.

But when we call is_valid_date_string and want to use logic in is_valid_month_string, we cannot directly call is_valid_month_string in is_valid_date_string, because at that time self.0 might be 1990-12-20 and is_valid_month_string will return false.

That's why I make the logic out to check_valid_month_string(value: &str). We can give value string for two case usage.

Maybe there is a better way to do this.

@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.

I think we need to be careful when reading the spec here - according to my reading, the spec does not fail on parsing a month component if the string contains a date at the end; it simply does not parse the rest of the string, and returns year and month to the caller of this algorithm.

@tigercosmos tigercosmos Nov 30, 2017 •

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.

@KiChjang
According to the spec:

A string is a valid month string representing a year year and month month if it consists of the following components in the given order:

  1. Four or more ASCII digits, representing year, where year > 0
  2. A U+002D HYPHEN-MINUS character (-)
  3. Two ASCII digits, representing the month month, in the range 1 ≤ month ≤ 12

Which means only "YYYY-MM" is valid to is_valid_month_string function

@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.

Note that it says "consists of the following components" - it's missing the only keyword. In other words, date strings are also valid month strings.

Furthermore, I believe we have agreed to use the parse a month component algorithm instead of the validation algorithm, so this part of the spec shouldn't be relevant to your implementation.

Comment thread components/script/dom/bindings/str.rs Outdated
}
},
_ => {
panic!("Month number must be in range 1~12.")

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.

Instead of panicking here, we can choose to return a Result<u32, ()> instead, and return Err(()) here.

<input id="step_attribute_is_invalid_value" type="month" value="2013-06" step="invalid_step_value" />
<input id="invalid_month_too_high" type="month" value="2013-13" />
<input id="invalid_month_too_low" type="month" value="2013-00" />
<input id="invalid_year_all_zerro" type="month" value="0000-10" />

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.

invalid_year_all_zero

<input id="valid" type="month" value="2011-11" min="2011-01" max="2011-12" />
<input id="invalid_value" type="month" value="invalid-month" min="2011-01" max="2011-12"/>
<input id="value_can_be_empty_string" type="month" value="2013-06" />
<input id="value_can_be_empty_string" type="month" value="" />

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 is this change necessary?

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 purpose in this test, is testing value to be empty string. But it set value for it.

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.

It sets the value as an empty string in the test below:

document.getElementById("value_can_be_empty_string").value = "";

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.

Why set empty below not set directly? I think it is not intuitive

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 may contact the author of this test and ask them this question. However I can venture a guess: the value of the value content attribute is the empty string at initialization, and setting it directly via the IDL setter ensures that we are testing specifically for the value sanitization algorithm.

<script>
test(function() {
assert_equals(document.getElementById("valid_value_1").value, "20133-12")
}, "year can be more than four number");

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.

"year can be more than four digits"


test(function() {
assert_equals(document.getElementById("valid_value_3").value, "0003-01")
}, "year must be four or more number even if it is zero");

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.

"year can contain prefixes of zero, as long as there are at least four digits"


test(function() {
assert_equals(document.getElementById("invalid_month_with_one_number").value, "");
}, "Month should be two number: If the value of the element is not a valid month string, then set it to the empty string instead.>");

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.

"Month should be two digits"

@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 29, 2017
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");
if (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.

I haven't looked closely enough on this change yet; will need some time before I can determine whether this is the actual change we want.

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.

This is in #19330
https://github.com/servo/servo/pull/19330/files#diff-a04db4d0de89c245a2878d38e99d51bdL52

will cause

▶ Unexpected subtest result in /html/semantics/forms/the-input-element/type-change-state.html:
  │ FAIL [expected PASS] change state from color to date
  │   → assert_equals: input.value should be "#000000" after change of state expected "#000000" but got ""
  │ FAIL [expected PASS] change state from color to month
  │   → assert_equals: input.value should be "#000000" after change of state expected "#000000" but got ""

But actually it should pass

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 are correct. This part of the spec makes it clear that the value sanitization algorithm should be run when there is a 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.

Uh, sorry, that was not the full story. Because the value sanitization algorithm is ran when the input.value is set, color type inputs will sanitize their values, and if it's a " foo\rbar " string, it would instead set the value as "#000000". This makes the expected value "#000000" even when you change the input type to text.

For date and month type inputs however, you're correct that it should expect the empty string instead.

I'll note that removing this check here isn't the correct fix though, we need to think of a more comprehensive way of testing this correctly -- the other PR is currently working on this.

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.

Since the other PR is already fixing this, we should revert the change here.

@highfive highfive removed the S-needs-code-changes Changes have not yet been made that were requested by a reviewer. label Nov 30, 2017
@tigercosmos

Copy link
Copy Markdown
Contributor Author

@KiChjang please check.

Comment thread components/script/dom/bindings/str.rs Outdated

// Step 1, 2
let year_int = year.parse::<u32>().map_err(|_| ())?;
if year.len() < 4 || year_int > 0 {

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.

If you check whether the year is greater than 0 then all valid years will be rejected.

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.

fixed

@KiChjang

KiChjang commented Dec 4, 2017 •

Copy link
Copy Markdown
Contributor

After reverting the changes to type-change-state.html, you'll need to run ./mach update-manifest, push the changes, squash, and r=me.

@tigercosmos

Copy link
Copy Markdown
Contributor Author

@KiChjang Done . Thanks.

@KiChjang

KiChjang commented Dec 4, 2017

Copy link
Copy Markdown
Contributor

@tigercosmos I don't seem to see the changes in type-change-state.html reverted?

@tigercosmos

Copy link
Copy Markdown
Contributor Author

Sorry. I lose reverting!
Update later.

@tigercosmos

Copy link
Copy Markdown
Contributor Author

@KiChjang Reverted! Thanks for your patient 👍

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #19379) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Dec 4, 2017
@KiChjang

KiChjang commented Dec 5, 2017

Copy link
Copy Markdown
Contributor

@tigercosmos Can you squash this into one commit? After that, this can finally land!

@tigercosmos

Copy link
Copy Markdown
Contributor Author

@KiChjang done


/// Validates this `DOMString` is a time string according to
/// <https://html.spec.whatwg.org/multipage/#valid-time-string>.
pub fn is_valid_time_string(&self) -> bool {

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 code shouldn't be here, the function is defined twice!

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.

weird.. I will update

@tigercosmos

Copy link
Copy Markdown
Contributor Author
  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors

@KiChjang

KiChjang commented Dec 5, 2017

Copy link
Copy Markdown
Contributor

@bors-servo r+

Thanks!

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 927fd1d 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. S-needs-rebase There are merge conflict errors. labels Dec 5, 2017
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 927fd1d with merge 68cefb1...

bors-servo pushed a commit that referenced this pull request Dec 5, 2017
implement  "Date type inputs", "Month type inputs"

<!-- Please describe your changes on the following line: -->
implement "Date type inputs", "Month type inputs"

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] `./mach test-unit` does not report any errors

<!-- 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/19385)
<!-- Reviewable:end -->
@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 68cefb1 to master...

@bors-servo
bors-servo merged commit 927fd1d into servo:master Dec 5, 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 5, 2017
@tigercosmos
tigercosmos deleted the b1 branch December 5, 2017 03:09
@CYBAI

CYBAI commented Dec 5, 2017

Copy link
Copy Markdown
Member

@tigercosmos @KiChjang WOW! Congrats!

@tigercosmos

Copy link
Copy Markdown
Contributor Author

@CYBAI thanks! Finally…

jdm pushed a commit to web-platform-tests/wpt that referenced this pull request Jan 4, 2018
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.

5 participants