mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #19330 - Eijebong:sanitize_color, r=KiChjang
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 -->
This commit is contained in:
commit
72e7f6095e
7 changed files with 24 additions and 188 deletions
|
@ -875,6 +875,26 @@ impl HTMLInputElement {
|
|||
content.strip_newlines();
|
||||
content.strip_leading_and_trailing_ascii_whitespace();
|
||||
}
|
||||
atom!("color") => {
|
||||
let mut textinput = self.textinput.borrow_mut();
|
||||
|
||||
let is_valid = {
|
||||
let content = textinput.single_line_content();
|
||||
let mut chars = content.chars();
|
||||
if content.len() == 7 && chars.next() == Some('#') {
|
||||
chars.all(|c| c.is_digit(16))
|
||||
} else {
|
||||
false
|
||||
}
|
||||
};
|
||||
|
||||
if is_valid {
|
||||
let content = textinput.single_line_content_mut();
|
||||
content.make_ascii_lowercase();
|
||||
} else {
|
||||
textinput.set_content("#000000".into());
|
||||
}
|
||||
}
|
||||
// TODO: Implement more value sanitization algorithms for different types of inputs
|
||||
_ => ()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue