Skip to content

[meta] Implement value sanitizations for different input modes #19172

Closed

Description

@KiChjang

#18262 laid the groundwork for this, but we're still missing value sanitizations for:

All of the missing algorithms above are expected to be implemented in this function:

// 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

  1. added
    A-content/dom
    B-meta
    E-less-complex
    on Nov 10, 2017
  2. highfive commented on Nov 10, 2017

    @highfive

    Hi! If you have any questions regarding this issue, feel free to make a comment here, or ask it in the #servo channel in IRC.

    If you intend to work on this issue, then add @highfive: assign me to your comment, and I'll assign this to you. 😄

  3. tigercosmos commented on Nov 10, 2017

    @tigercosmos
    Contributor

    @highfive: assign me

  4. highfive commented on Nov 10, 2017

    @highfive

    Hey @tigercosmos! Thanks for your interest in working on this issue. It's now assigned to you!

  5. added
    C-assigned
    on Nov 10, 2017
  6. tigercosmos commented on Nov 10, 2017

    @tigercosmos
    Contributor

    @KiChjang Can I divide it to several parts and solve them one by one? Maybe two or three?

  7. KiChjang commented on Nov 10, 2017

    @KiChjang
    ContributorAuthor

    @tigercosmos Sure! Just comment and make a list of the ones that you'd like to solve.

  8. removed
    C-assigned
    on Nov 10, 2017
  9. KiChjang commented on Nov 10, 2017

    @KiChjang
    ContributorAuthor

    Keeping this open for other potential contributors.

  10. tigercosmos commented on Nov 11, 2017

    @tigercosmos
    Contributor

    Seems min max step attributes have not implemented?
    Where I guess it should be in:

    fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
    self.super_type().unwrap().attribute_mutated(attr, mutation);
    match attr.local_name() {

  11. KiChjang commented on Nov 11, 2017

    @KiChjang
    ContributorAuthor

    That is incorrect. I can find them under the HTMLInputElementMethods trait implementation.

    // https://html.spec.whatwg.org/multipage/#dom-input-max
    make_getter!(Max, "max");
    // https://html.spec.whatwg.org/multipage/#dom-input-max
    make_setter!(SetMax, "max");

  12. tigercosmos commented on Nov 11, 2017

    @tigercosmos
    Contributor

    That just get the value. But we need to do something? e.g. min should be number.

  13. KiChjang commented on Nov 11, 2017

    @KiChjang
    ContributorAuthor

    I assume the reason why you're asking is because the spec mentions max, min and step attributes 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, min and step attribute 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.

  14. 29 remaining items

  15. cursedquail commented on Jan 9, 2018

    @cursedquail

    👍 I just opened one.

  16. added 2 commits that reference this issue on Jan 10, 2018
  17. tigercosmos commented on Jan 10, 2018

    @tigercosmos
    Contributor

    let me finish the last one range type inputs
    @highfive: assign me

  18. added
    C-assigned
    on Jan 10, 2018
  19. highfive commented on Jan 10, 2018

    @highfive

    Hey @tigercosmos! Thanks for your interest in working on this issue. It's now assigned to you!

  20. tigercosmos commented on Jan 13, 2018

    @tigercosmos
    Contributor

    I have opened the last one PR in this issue.
    Once #19761 finished, this will closed.

  21. added a commit that references this issue on Jan 17, 2018
    4f09987
  22. CYBAI commented on Sep 25, 2018

    @CYBAI
    Member
  23. tigercosmos commented on Sep 25, 2018

    @tigercosmos
    Contributor

    Yes, let's reopen the issue.

  24. removed
    C-assigned
    on Sep 25, 2018
  25. KiChjang commented on Sep 25, 2018

    @KiChjang
    ContributorAuthor

    I've instead filed #21810, which contains other things that also needs attention for value sanitization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-content/domB-metaE-less-complex

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions