Skip to content

number input type validations - #19730

Merged
bors-servo merged 1 commit into
servo:masterfrom
cursedquail:19172-number-input-type-validations
Jan 10, 2018
Merged

bors-servo merged 1 commit into
servo:masterfrom
cursedquail:19172-number-input-type-validations

Conversation

@cursedquail

@cursedquail cursedquail commented Jan 9, 2018 •

Copy link
Copy Markdown

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.


  • There are tests for these changes

This change is Reviewable

@highfive

highfive commented Jan 9, 2018

Copy link
Copy Markdown

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.

@highfive

highfive commented Jan 9, 2018

Copy link
Copy Markdown

Heads up! This PR modifies the following files:

  • @asajeffrey: components/script/dom/htmlinputelement.rs, components/script/dom/bindings/str.rs
  • @fitzgen: components/script/dom/htmlinputelement.rs, components/script/dom/bindings/str.rs
  • @KiChjang: components/script/dom/htmlinputelement.rs, components/script/dom/bindings/str.rs

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Jan 9, 2018
@highfive

highfive commented Jan 9, 2018

Copy link
Copy Markdown

warning Warning warning

  • These commits modify script code, but no tests are modified. Please consider adding a test!

@tigercosmos

Copy link
Copy Markdown
Contributor

if you use "fix" keyword, the issue will be closed once the PR merged.
But this PR only do number part. There is still range one need to do.
In this case, we should just mention the issue than adding keyword fix or close

Comment thread components/script/dom/bindings/str.rs Outdated
/// 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>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better

let parsed_result = match  input.parse::<f64>() {
// ... 
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! Fixed.

Comment thread components/script/dom/bindings/str.rs Outdated
if input.starts_with("+") {
return false;
}
return true;

@tigercosmos tigercosmos Jan 9, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess no need return here?

true

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 . I guess I'm still used to C++ with it's explicit return.

@tigercosmos

Copy link
Copy Markdown
Contributor

If you not change anythings in /tests, we don't need to run ./mach update-manifest

@tigercosmos

Copy link
Copy Markdown
Contributor
Running the WPT lint on ./tests/wpt/mozilla/tests/...
Checking files for tidiness...
./components/script/dom/bindings/str.rs:307: link to WHATWG may break in the future, use this format instead: https://html.spec.whatwg.org/multipage/#valid-floating-point-number
./components/script/dom/bindings/str.rs:21: use statement is not in alphabetical order
	expected: std::str::{Bytes, FromStr}
	found: std::f64

@cursedquail

Copy link
Copy Markdown
Author

test-tidy issues have been fixed, build reports no errors, and I've cleaned up the comments a bit.

@cursedquail cursedquail changed the title [WIP] number input type validations number input type validations Jan 9, 2018
@tigercosmos

Copy link
Copy Markdown
Contributor

I think there might be some result change when you run

./mach test-wpt tests/wpt/web-platform-tests/html/semantics/forms/the-input-element/

I expect at least number.html changed.

If you find some test case from expect Failed to Pass.
Delete the pair in /Users/tigercosmos/servo/tests/wpt/metadata/html/semantics/forms/the-input-element/number.html.ini

If all cases in .ini PASS, just delete the file. Other files are the same way.

@tigercosmos

tigercosmos commented Jan 10, 2018 •

Copy link
Copy Markdown
Contributor

Looks Good!
r? @KiChjang

@highfive highfive assigned KiChjang and unassigned emilio Jan 10, 2018

@KiChjang KiChjang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I have some small nits here, fix those, and you can r=me :)

Comment thread components/script/dom/bindings/str.rs Outdated
if input.starts_with("+") {
return false;
}
true

@KiChjang KiChjang Jan 10, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread components/script/dom/bindings/str.rs Outdated
/// 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>() {

@KiChjang KiChjang Jan 10, 2018 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can actually benefit from using map_or as well:

input.parse::<f64>().ok().map_or(false, |val| {
    // conditions...
})

@KiChjang KiChjang added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jan 10, 2018
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Jan 10, 2018
@cursedquail

Copy link
Copy Markdown
Author

I've made the changes 👍

@KiChjang

Copy link
Copy Markdown
Contributor

Alright! Next step is to squash your commits, and I'll happily land your PR :)

@cursedquail
cursedquail force-pushed the 19172-number-input-type-validations branch from aa81717 to 5b6e821 Compare January 10, 2018 02:08
@cursedquail

Copy link
Copy Markdown
Author

Done! I also rebased it onto master 😄

@KiChjang

Copy link
Copy Markdown
Contributor

@bors-servo r+

Thanks for your contribution!

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 5b6e821 has been approved by KiChjang

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jan 10, 2018
@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 5b6e821 with merge 3e0e9fc...

bors-servo pushed a commit that referenced this pull request Jan 10, 2018
…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 -->
@bors-servo

Copy link
Copy Markdown
Contributor

💔 Test failed - mac-dev-unit

@highfive highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Jan 10, 2018
@KiChjang

Copy link
Copy Markdown
Contributor

@bors-servo retry

  • Gecko media

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 5b6e821 with merge afe298b...

bors-servo pushed a commit that referenced this pull request Jan 10, 2018
…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 -->
@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Jan 10, 2018
@bors-servo

Copy link
Copy Markdown
Contributor

☀️ 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
Approved by: KiChjang
Pushing afe298b to master...

@bors-servo
bors-servo merged commit 5b6e821 into servo:master Jan 10, 2018
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Jan 10, 2018
@cursedquail
cursedquail deleted the 19172-number-input-type-validations branch January 10, 2018 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants