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 upIssue 21810/improve validation methods #24626
Conversation
highfive
commented
Nov 3, 2019
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @asajeffrey (or someone else) soon. |
highfive
commented
Nov 3, 2019
|
Heads up! This PR modifies the following files:
|
|
I'm in favour of unit tests for small, self-contained routines like this. |
| /// https://html.spec.whatwg.org/multipage/#valid-month-string | ||
| pub fn is_valid_month_string(&self) -> bool { | ||
| parse_month_string(&self.0).is_ok() |
This comment has been minimized.
This comment has been minimized.
jdm
Nov 12, 2019
Member
Whoops, I missed reading this commit. While in general I'm in favour of using state machines for clarity of purpose and avoiding invalid states, I find this one to be difficult to follow. I'm not sure if it's the names of the states, or the repetition between them, or something else, but my eyes keep glazing over when I try to follow the logic. Given how straightforward the specification text is, I'm not exactly sure what to recommend.
This comment has been minimized.
This comment has been minimized.
jdm
Nov 12, 2019
Member
My reading of the specification is that the parsing algorithm for month strings is the same as the validation algorithm for month strings, so I don't see a good reason to reimplement this particular algorithm. Presumably there are other input types where they diverge?
This comment has been minimized.
This comment has been minimized.
glowe
Nov 20, 2019
•
Author
My reading of the specification is that the parsing algorithm for month strings is the same as the validation algorithm for month strings, so I don't see a good reason to reimplement this particular algorithm. Presumably there are other input types where they diverge?
Actually, the tests passed for the original implementations of the date validation functions, so I judge them to be equivalent to the specifications. The original issue #21810 recommended reimplementing all of these functions, but I think that recommendation was based on the premise that the functions might be incorrect. I've gone ahead and reverted the change to is_valid_month_string.
The lone validation function with an issue was is_valid_floating_point_number_string, so I've fixed it. Please take another look and let me know what you think.
1986ddb
to
8abbae1
|
@bors-servo r+ |
|
|
…r=jdm Issue 21810/improve validation methods <!-- Please describe your changes on the following line: --> This is a start at addressing #21810. I'm putting these changes out early to get some feedback on the following items: 1. I added unit tests for the validation methods mentioned in #21810, because I couldn't tell whether any of the existing WPT tests covered them. Are these tests worthwhile? Are any of them unnecessary? 2. I changed the implementation for `is_valid_floating_point_number_string` so that it passed the tests. The previous version of the function wasn't restrictive enough (it allowed certain whitespace characters before the number string). 3. I changed the catch-all condition in `htmlinputelement.rs` to account for the remaining input types that don't have a value sanitization algorithm. This last change seems good to me since we won't be able to add a new input type without adding it to the case and checking the spec for an algorithm. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21810 <!-- Either: --> - [x] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
|
|
|
Hmm, looks like we now fail a test that we used to pass:
This can be reproduced with |
Thanks for identifying the failing test for me. We are now failing on a bounds check: Interestingly, I tried this specific test on Firefox 70.0.1 and it failed (http://wpt.live/html/semantics/forms/the-input-element/number.html). However, this test passes in the latest Chrome and Safari browsers. Here's what I propose we do next (let me know what you think): 1.) I'll update the code to handle the bounds check, probably by delegating to the parsing code after verifying that there's no leading whitespace. The specification mentions that the whitespace characters can be EDIT: |
Replaced catch-all with explicit case for inputs that do not have a value sanitization algorithm. This should prevent us from forgetting to implement a sanitization for an input, since they must all be accounted for in the match expression.
Fixes an issue where DOMString::is_valid_floating_point_number_string was returning true for strings that began with whitespace characters- TAB, LF, FF, or CR. Also added a unit test to cover this since the corresponding web-platform-tests are incomplete.
8abbae1
to
576f51f
|
Those choices seem reasonable! You can also include the WPT changes in this PR, because we automatically sync them upstream when they merge in our vendored copy. |
|
And FYI https://wpt.fyi/results/html/semantics/forms/the-input-element/number.html?label=master&label=experimental&aligned&q=number.html backs up your results with respect to Firefox's test results. |
Thanks! I did not know that. I've enhanced the number input WPT to include those additional cases and deleted the unit test since it's redundant coverage. |
|
Opened new PR for upstreamable changes. Completed upstream sync of web-platform-test changes at web-platform-tests/wpt#20575. |
|
@bors-servo r+ |
|
|
…r=jdm Issue 21810/improve validation methods <!-- Please describe your changes on the following line: --> This is a start at addressing #21810. I'm putting these changes out early to get some feedback on the following items: 1. I added unit tests for the validation methods mentioned in #21810, because I couldn't tell whether any of the existing WPT tests covered them. Are these tests worthwhile? Are any of them unnecessary? 2. I changed the implementation for `is_valid_floating_point_number_string` so that it passed the tests. The previous version of the function wasn't restrictive enough (it allowed certain whitespace characters before the number string). 3. I changed the catch-all condition in `htmlinputelement.rs` to account for the remaining input types that don't have a value sanitization algorithm. This last change seems good to me since we won't be able to add a new input type without adding it to the case and checking the spec for an algorithm. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21810 <!-- Either: --> - [x] There are tests for these changes <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
|
|
glowe commentedNov 3, 2019
•
edited
This is a start at addressing #21810. I'm putting these changes out early to get some feedback on the following items:
is_valid_floating_point_number_stringso that it passed the tests. The previous version of the function wasn't restrictive enough (it allowed certain whitespace characters before the number string).htmlinputelement.rsto account for the remaining input types that don't have a value sanitization algorithm. This last change seems good to me since we won't be able to add a new input type without adding it to the case and checking the spec for an algorithm../mach build -ddoes not report any errors./mach test-tidydoes not report any errors