Repository navigation
Add a sanitize_value implementation for the color input - #19330
Conversation
5c63f86 to
f05d857
Compare
KiChjang
left a comment
There was a problem hiding this 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)) |
There was a problem hiding this comment.
Instead of using fold here, we can use all.
There was a problem hiding this comment.
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.
Why does this need to be mutable?
There was a problem hiding this comment.
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.
| } | ||
| atom!("color") => { | ||
| let mut textinput = self.textinput.borrow_mut(); | ||
| let content = textinput.get_content(); |
There was a problem hiding this comment.
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! Details |
|
\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
#000000in it.This change is