Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd a sanitize_value implementation for the color input #19330
Conversation
highfive
commented
Nov 22, 2017
|
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| 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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
This comment has been minimized.
KiChjang
Nov 22, 2017
Member
get_content() clones the value, so let's use single_line_content() here.
|
About the test failure, should I change the hash myself ? |
|
@bors-servo r+ Thanks! |
|
|
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 -->
|
|
|
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.
|
@bors-servo r+ |
|
|
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 -->
|
|
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]
Eijebong commentedNov 22, 2017
•
edited by SimonSapin
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