Repository navigation
number input type validations - #19730
Conversation
|
Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @emilio (or someone else) soon. |
|
Heads up! This PR modifies the following files:
|
|
if you use "fix" keyword, the issue will be closed once the PR merged. |
| /// The rust default String::parse<f64>() is extremely close, and this just fills in the gaps. | ||
| pub fn is_valid_number_string(&self) -> bool { | ||
| let input = &self.0; | ||
| let parsed_result = input.parse::<f64>(); |
There was a problem hiding this comment.
It would be better
let parsed_result = match input.parse::<f64>() {
// ...
}
| if input.starts_with("+") { | ||
| return false; | ||
| } | ||
| return true; |
There was a problem hiding this comment.
I guess no need return here?
true
There was a problem hiding this comment.
👍 . I guess I'm still used to C++ with it's explicit return.
|
If you not change anythings in |
|
|
|
|
I think there might be some result change when you run I expect at least If you find some test case from expect Failed to Pass. If all cases in |
|
Looks Good! |
KiChjang
left a comment
There was a problem hiding this comment.
Great work! I have some small nits here, fix those, and you can r=me :)
| if input.starts_with("+") { | ||
| return false; | ||
| } | ||
| true |
There was a problem hiding this comment.
These lines of if expressions can actually be all simplified to:
!(val.is_infinite() || val.is_nan() || input.ends_with('.') || input.starts_with('+'))Or you can use DeMorgan's law and use && instead.
| /// https://html.spec.whatwg.org/multipage/#valid-floating-point-number | ||
| pub fn is_valid_number_string(&self) -> bool { | ||
| let input = &self.0; | ||
| match input.parse::<f64>() { |
There was a problem hiding this comment.
This can actually benefit from using map_or as well:
input.parse::<f64>().ok().map_or(false, |val| {
// conditions...
})|
I've made the changes 👍 |
|
Alright! Next step is to squash your commits, and I'll happily land your PR :) |
aa81717 to
5b6e821
Compare
|
Done! I also rebased it onto master 😄 |
|
@bors-servo r+ Thanks for your contribution! |
|
📌 Commit 5b6e821 has been approved by |
…r=KiChjang number input type validations I used rust's builtin float parser to implement this. Rust's parser is more permissive than what browsers support (in this case), so I added some code to handle those edge cases. This passes all the prewritten test cases locally, but I fell asleep last night before updating the manifests 😅 --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes are part of #19172 <!-- Either: --> - [X] There are tests for these changes <!-- 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/19730) <!-- Reviewable:end -->
|
💔 Test failed - mac-dev-unit |
|
@bors-servo retry
|
…r=KiChjang number input type validations I used rust's builtin float parser to implement this. Rust's parser is more permissive than what browsers support (in this case), so I added some code to handle those edge cases. This passes all the prewritten test cases locally, but I fell asleep last night before updating the manifests 😅 --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes are part of #19172 <!-- Either: --> - [X] There are tests for these changes <!-- 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/19730) <!-- Reviewable:end -->
|
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
I used rust's builtin float parser to implement this. Rust's parser is more permissive than what browsers support (in this case), so I added some code to handle those edge cases.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errorsThis change is