-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Conversation
5c63f86
to
f05d857
Compare
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
About the test failure, should I change the hash myself ? |
f05d857
to
daf66aa
Compare
@bors-servo r+ Thanks! |
📌 Commit daf66aa has been approved by |
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 -->
💔 Test failed - linux-rel-wpt |
Looks like we just hit the jackpot for passing tests!
|
\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.
daf66aa
to
05c4e08
Compare
@bors-servo r+ |
📌 Commit 05c4e08 has been approved by |
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 -->
☀️ 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 |
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]
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 arehexadecimal. If all those requirements are met, we lowercase the
content, otherwise we put
#000000
in it.This change is![Reviewable](https://camo.githubusercontent.com/23b05f5fb48215c989e92cc44cf6512512d083132bd3daf689867c8d9d386888/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)