diff options
author | ffwff <mogamiriver@tuta.io> | 2019-05-29 08:21:49 +0700 |
---|---|---|
committer | ffwff <mogamiriver@tuta.io> | 2019-05-29 23:07:17 +0700 |
commit | 3508140929391d9991add362c385bab1adc580a2 (patch) | |
tree | 41f94d1d404442cd18a21c593f559702f6dd0fef /components/script/dom | |
parent | 84ec1316c90a29f07c60e10f78ba4d9f3185bef8 (diff) | |
download | servo-3508140929391d9991add362c385bab1adc580a2.tar.gz servo-3508140929391d9991add362c385bab1adc580a2.zip |
Add value sanitization algorithm for input[type="email"]
Handle "Multiple" attribute for email value sanitization
Fix code formatting
Tests for email value sanitization should pass
Make failing wpt tests pass
Change new_value => sanitized
Diffstat (limited to 'components/script/dom')
-rwxr-xr-x | components/script/dom/htmlinputelement.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index a7d73dd404e..26a5c41a26c 100755 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -63,7 +63,7 @@ use std::cell::Cell; use std::ops::Range; use style::attr::AttrValue; use style::element_state::ElementState; -use style::str::split_commas; +use style::str::{split_commas, str_join}; const DEFAULT_SUBMIT_VALUE: &'static str = "Submit"; const DEFAULT_RESET_VALUE: &'static str = "Reset"; @@ -1195,6 +1195,24 @@ impl HTMLInputElement { InputType::Range => { value.set_best_representation_of_the_floating_point_number(); }, + InputType::Email => { + if !self.Multiple() { + value.strip_newlines(); + value.strip_leading_and_trailing_ascii_whitespace(); + } else { + let sanitized = str_join( + split_commas(value).map(|token| { + let mut token = DOMString::from_string(token.to_string()); + token.strip_newlines(); + token.strip_leading_and_trailing_ascii_whitespace(); + token + }), + ",", + ); + value.clear(); + value.push_str(sanitized.as_str()); + } + }, _ => (), } } |