Repository navigation
Description
#18262 laid the groundwork for this, but we're still missing value sanitizations for:
- Date type inputs (implement "Date type inputs", "Month type inputs" #19385)
- Month type inputs (implement "Date type inputs", "Month type inputs" #19385)
- Week type inputs (implement valid week string #19559)
- Time type inputs (Implemented sanitize_value for time input #19379)
- Date-time type inputs (implement valid DatetimeLocal input #19602)
- Number type inputs and range type inputs (number input type validations #19730, implement range input sanitization #19761)
- Color type inputs (Add a sanitize_value implementation for the color input #19330)
- E-Mail type inputs
All of the missing algorithms above are expected to be implemented in this function:
servo/components/script/dom/htmlinputelement.rs
Lines 1125 to 1190 in 6e844f2
| // https://html.spec.whatwg.org/multipage/#value-sanitization-algorithm | |
| fn sanitize_value(&self, value: &mut DOMString) { | |
| match self.input_type() { | |
| InputType::Text | InputType::Search | InputType::Tel | InputType::Password => { | |
| value.strip_newlines(); | |
| }, | |
| InputType::Url => { | |
| value.strip_newlines(); | |
| value.strip_leading_and_trailing_ascii_whitespace(); | |
| }, | |
| InputType::Date => { | |
| if !value.is_valid_date_string() { | |
| value.clear(); | |
| } | |
| }, | |
| InputType::Month => { | |
| if !value.is_valid_month_string() { | |
| value.clear(); | |
| } | |
| }, | |
| InputType::Week => { | |
| if !value.is_valid_week_string() { | |
| value.clear(); | |
| } | |
| }, | |
| InputType::Color => { | |
| let is_valid = { | |
| let mut chars = value.chars(); | |
| if value.len() == 7 && chars.next() == Some('#') { | |
| chars.all(|c| c.is_digit(16)) | |
| } else { | |
| false | |
| } | |
| }; | |
| if is_valid { | |
| value.make_ascii_lowercase(); | |
| } else { | |
| *value = "#000000".into(); | |
| } | |
| }, | |
| InputType::Time => { | |
| if !value.is_valid_time_string() { | |
| value.clear(); | |
| } | |
| }, | |
| InputType::DatetimeLocal => { | |
| if value | |
| .convert_valid_normalized_local_date_and_time_string() | |
| .is_err() | |
| { | |
| value.clear(); | |
| } | |
| }, | |
| InputType::Number => { | |
| if !value.is_valid_floating_point_number_string() { | |
| value.clear(); | |
| } | |
| }, | |
| // https://html.spec.whatwg.org/multipage/#range-state-(type=range):value-sanitization-algorithm | |
| InputType::Range => { | |
| value.set_best_representation_of_the_floating_point_number(); | |
| }, | |
| _ => (), | |
| } | |
| } |
The implementation for these value sanitizations are given by the spec, which I have linked accordingly. When each of these are implemented, some subtests under tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/type-change-state.html should be expected to PASS instead. Some other tests under the same directory may also pass as a result of a correct implementation.
If you want to help out with this, please comment on this issue or reach out on IRC (#servo in irc.mozilla.org), and we'll find one which is interesting to you; or, you can also file an issue and mention this one, and I'll get it assigned to you.
Activity
highfive commentedon Nov 10, 2017
Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the
#servochannel in IRC.If you intend to work on this issue, then add
@highfive: assign meto your comment, and I'll assign this to you. 😄tigercosmos commentedon Nov 10, 2017
@highfive: assign me
highfive commentedon Nov 10, 2017
Hey @tigercosmos! Thanks for your interest in working on this issue. It's now assigned to you!
tigercosmos commentedon Nov 10, 2017
@KiChjang Can I divide it to several parts and solve them one by one? Maybe two or three?
KiChjang commentedon Nov 10, 2017
@tigercosmos Sure! Just comment and make a list of the ones that you'd like to solve.
KiChjang commentedon Nov 10, 2017
Keeping this open for other potential contributors.
tigercosmos commentedon Nov 11, 2017
Seems
minmaxstepattributes have not implemented?Where I guess it should be in:
servo/components/script/dom/htmlinputelement.rs
Lines 896 to 899 in a3f2fae
KiChjang commentedon Nov 11, 2017
That is incorrect. I can find them under the
HTMLInputElementMethodstrait implementation.servo/components/script/dom/htmlinputelement.rs
Lines 496 to 500 in 33fa728
tigercosmos commentedon Nov 11, 2017
That just get the value. But we need to do something? e.g. min should be number.
KiChjang commentedon Nov 11, 2017
I assume the reason why you're asking is because the spec mentions
max,minandstepattributes should be valid date strings? You can safely ignore that part - the spec is written with different target audiences in mind: HTML authors (which is to say programmers who write HTML) and HTML implementors (us). Those requirements are for HTML authors, since they do not mention how user agents (browsers) should act when they are invalid.In addition, the spec defines the value sanitization algorithm as "if the value of the element is not a valid date string, then set it to the empty string instead". The
max,minandstepattribute stuff is not part of the value sanitization algorithm.The valid date strings algorithm is what you will need to implement, and I think the appropriate place to put that algorithm would be in
components/style/attr.rs.29 remaining items
cursedquail commentedon Jan 9, 2018
👍 I just opened one.
Auto merge of #19730 - NLincoln:19172-number-input-type-validations, …
Auto merge of #19730 - NLincoln:19172-number-input-type-validations, …
tigercosmos commentedon Jan 10, 2018
let me finish the last one
range type inputs@highfive: assign me
highfive commentedon Jan 10, 2018
Hey @tigercosmos! Thanks for your interest in working on this issue. It's now assigned to you!
tigercosmos commentedon Jan 13, 2018
I have opened the last one PR in this issue.
Once #19761 finished, this will closed.
Auto merge of #19761 - tigercosmos:m1, r=KiChjang
CYBAI commentedon Sep 25, 2018
Is
E-Mailsanitization missing for thismetaissue?Ref: https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type=email)
tigercosmos commentedon Sep 25, 2018
Yes, let's reopen the issue.
KiChjang commentedon Sep 25, 2018
I've instead filed #21810, which contains other things that also needs attention for value sanitization.