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

Add a sanitize_value implementation for the color input #19330

Merged
merged 1 commit into from
Nov 23, 2017

Conversation

Eijebong
Copy link
Contributor

@Eijebong Eijebong commented Nov 22, 2017

I had to change the test a little bit to avoid some failures due to
color and text both having a sanitizedValue which was making the test
use the first assertion instead of the second one in some cases.

The sanitize_value implementation is pretty simple, we iterate over the
content and checks that the content is 7 characters long, that the first
character is a # and then that all the following characters are
hexadecimal. If all those requirements are met, we lowercase the
content, otherwise we put #000000 in it.


This change is Reviewable

@highfive
Copy link

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/htmlinputelement.rs
  • @KiChjang: components/script/dom/htmlinputelement.rs

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

@KiChjang KiChjang left a comment

Choose a reason for hiding this comment

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

This is a great start! I just have a couple of nits below. r=me after the change.

let is_valid = {
let mut chars = content.chars();
if content.len() == 7 && chars.next() == Some('#') {
chars.fold(true, |v, c| v && c.is_digit(16))
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using fold here, we can use all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, didn't know about that :)

let mut textinput = self.textinput.borrow_mut();
let content = textinput.get_content();
let is_valid = {
let mut chars = content.chars();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need to be mutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The iterator needs to be mutable because we're calling .next() on it to discard the # before checking if every other character in it is a valid hex digit.

@@ -875,6 +875,24 @@ impl HTMLInputElement {
content.strip_newlines();
content.strip_leading_and_trailing_ascii_whitespace();
}
atom!("color") => {
let mut textinput = self.textinput.borrow_mut();
let content = textinput.get_content();
Copy link
Contributor

Choose a reason for hiding this comment

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

get_content() clones the value, so let's use single_line_content() here.

@KiChjang KiChjang assigned KiChjang and unassigned pcwalton Nov 22, 2017
@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 22, 2017
@Eijebong
Copy link
Contributor Author

About the test failure, should I change the hash myself ?

@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 22, 2017
@KiChjang
Copy link
Contributor

@bors-servo r+

Thanks!

@bors-servo
Copy link
Contributor

📌 Commit daf66aa 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 Nov 22, 2017
@bors-servo
Copy link
Contributor

⌛ Testing commit daf66aa with merge 199aa27...

bors-servo pushed a commit that referenced this pull request Nov 22, 2017
Add a sanitize_value implementation for the color input

I had to change the test a little bit to avoid some failures due to
color and text both having a sanitizedValue which was making the test
use the first assertion instead of the second one in some cases.

The sanitize_value implementation is pretty simple, we iterate over the
content and checks that the content is 7 characters long, that the first
character is a `#` and then that all the following characters are
hexadecimal. If all those requirements are met, we lowercase the
content, otherwise we put `#000000` in it.

<!-- 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/19330)
<!-- Reviewable:end -->
@bors-servo
Copy link
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 Nov 22, 2017
@KiChjang
Copy link
Contributor

KiChjang commented Nov 22, 2017

Looks like we just hit the jackpot for passing tests!

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

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

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Empty value should return #000000

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Missing value should return #000000

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Valid simple color (containing LATIN CAPITAL LETTERS): should return #ffffff (converted to ASCII lowercase)

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Zero-padding

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid simple color: not 7 characters long

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid simple color: no starting # sign

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid simple color: non ASCII hex digits

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid simple color: foobar

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: trailing Null (U+0000)

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: trailing ;

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: leading space

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: trailing space

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: leading+trailing spaces

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: keyword crimson

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: keyword bisque

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: keyword currentColor

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: keyword transparent

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: keyword ActiveBorder

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: keyword inherit

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: rgb(1,1,1)

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: rgb(1,1,1,1)

  ▶ Unexpected subtest result in /html/semantics/forms/the-input-element/color.html:
  └ PASS [expected FAIL] Invalid color: PILE OF POO (U+1F4A9)

@Eijebong
Copy link
Contributor Author

\o/ Didn't think about running other tests, I'll change the expectations :)

I had to change the test a little bit to avoid some failures due to
color and text both having a sanitizedValue which was making the test
use the first assertion instead of the second one in some cases.

The sanitize_value implementation is pretty simple, we iterate over the
content and checks that the content is 7 characters long, that the first
character is a `#` and then that all the following characters are
hexadecimal. If all those requirements are met, we lowercase the
content, otherwise we put `#000000` in it.
@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. labels Nov 22, 2017
@KiChjang
Copy link
Contributor

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit 05c4e08 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 Nov 23, 2017
@bors-servo
Copy link
Contributor

⌛ Testing commit 05c4e08 with merge 72e7f60...

bors-servo pushed a commit that referenced this pull request Nov 23, 2017
Add a sanitize_value implementation for the color input

I had to change the test a little bit to avoid some failures due to
color and text both having a sanitizedValue which was making the test
use the first assertion instead of the second one in some cases.

The sanitize_value implementation is pretty simple, we iterate over the
content and checks that the content is 7 characters long, that the first
character is a `#` and then that all the following characters are
hexadecimal. If all those requirements are met, we lowercase the
content, otherwise we put `#000000` in it.

<!-- 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/19330)
<!-- Reviewable:end -->
@bors-servo
Copy link
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 72e7f60 to master...

@bors-servo bors-servo merged commit 05c4e08 into servo:master Nov 23, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Nov 23, 2017
jdm pushed a commit to web-platform-tests/wpt that referenced this pull request Jan 4, 2018
I had to change the test a little bit to avoid some failures due to
color and text both having a sanitizedValue which was making the test
use the first assertion instead of the second one in some cases.

The sanitize_value implementation is pretty simple, we iterate over the
content and checks that the content is 7 characters long, that the first
character is a `#` and then that all the following characters are
hexadecimal. If all those requirements are met, we lowercase the
content, otherwise we put `#000000` in it.

Upstreamed from servo/servo#19330 [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.

None yet

5 participants