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
Member

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

highfive commented Nov 22, 2017

Heads up! This PR modifies the following files:

  • @fitzgen: components/script/dom/htmlinputelement.rs
  • @KiChjang: components/script/dom/htmlinputelement.rs
@Eijebong Eijebong force-pushed the Eijebong:sanitize_color branch from 5c63f86 to f05d857 Nov 22, 2017
Copy link
Member

KiChjang left a comment

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))

This comment has been minimized.

@KiChjang

KiChjang Nov 22, 2017

Member

Instead of using fold here, we can use all.

This comment has been minimized.

@Eijebong

Eijebong Nov 22, 2017

Author Member

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();

This comment has been minimized.

@KiChjang

KiChjang Nov 22, 2017

Member

Why does this need to be mutable?

This comment has been minimized.

@Eijebong

Eijebong Nov 22, 2017

Author Member

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();

This comment has been minimized.

@KiChjang

KiChjang Nov 22, 2017

Member

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

@Eijebong
Copy link
Member Author

Eijebong commented Nov 22, 2017

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

@Eijebong Eijebong force-pushed the Eijebong:sanitize_color branch from f05d857 to daf66aa Nov 22, 2017
@KiChjang
Copy link
Member

KiChjang commented Nov 22, 2017

@bors-servo r+

Thanks!

@bors-servo
Copy link
Contributor

bors-servo commented Nov 22, 2017

📌 Commit daf66aa has been approved by KiChjang

@bors-servo
Copy link
Contributor

bors-servo commented Nov 22, 2017

Testing commit daf66aa with merge 199aa27...

bors-servo added 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

bors-servo commented Nov 22, 2017

💔 Test failed - linux-rel-wpt

@KiChjang
Copy link
Member

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
Member Author

Eijebong commented Nov 22, 2017

\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.
@Eijebong Eijebong force-pushed the Eijebong:sanitize_color branch from daf66aa to 05c4e08 Nov 22, 2017
@KiChjang
Copy link
Member

KiChjang commented Nov 23, 2017

@bors-servo
Copy link
Contributor

bors-servo commented Nov 23, 2017

📌 Commit 05c4e08 has been approved by KiChjang

@bors-servo
Copy link
Contributor

bors-servo commented Nov 23, 2017

Testing commit 05c4e08 with merge 72e7f60...

bors-servo added 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

bors-servo commented Nov 23, 2017

@bors-servo bors-servo merged commit 05c4e08 into servo:master Nov 23, 2017
2 of 3 checks passed
2 of 3 checks passed
continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
homu Test successful
Details
@tigercosmos tigercosmos mentioned this pull request Nov 29, 2017
3 of 3 tasks complete
jdm added 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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.