Skip to content

Saturate if nth-child value is out of range #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 19, 2017

Conversation

Manishearth
Copy link
Member

@Manishearth Manishearth commented Sep 18, 2017

Reusing our tokenizer because it already saturates.

There is no way to reliably get the error details from "-12034".parse(), since the error type is opaque and the description strings may change.

This fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1401016

A less risky but also less correct fix is to simply return an error when .parse() fails.

r? @SimonSapin

Don't land until I can get a try run; nth-child has weird tokenization rules that we need to respect here (which is why I'm creating a new tokenizer in the first place)


This change is Reviewable

@Manishearth
Copy link
Member Author

@SimonSapin
Copy link
Member

@bors-servo r+

@bors-servo
Copy link
Contributor

📌 Commit 07332bb has been approved by SimonSapin

@bors-servo
Copy link
Contributor

⌛ Testing commit 07332bb with merge a8edcd9...

bors-servo pushed a commit that referenced this pull request Sep 19, 2017
Saturate if nth-child value is out of range

Reusing our tokenizer because it already saturates.

There is no way to reliably get the error details from `"-12034".parse()`, since the error type is opaque and the description strings may change.

This fixes https://bugzilla.mozilla.org/show_bug.cgi?id=1401016

A less risky but also less correct fix is to simply return an error when `.parse()` fails.

r? @SimonSapin

Don't land until I can get a try run; nth-child has weird tokenization rules that we need to respect here (which is why I'm creating a new tokenizer in the first place)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/198)
<!-- Reviewable:end -->
Copy link
Contributor

@heycam heycam left a comment

Choose a reason for hiding this comment

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

Looks good.

fn parse_number_saturate(string: &str) -> Result<i32, ()> {
let mut input = ParserInput::new(string);
let mut parser = Parser::new(&mut input);
let int = if let Ok(&Token::Number {int_value: Some(int), ..})
Copy link
Contributor

Choose a reason for hiding this comment

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

The structure here feels a little weird. How about:

  let next = parser.next_including_whitespace_and_comments();
  if let Ok(&Token::Number {int_value: Some(int), ..}) = next {
    if !parser.is_exhausted() {
      return Ok(int);
    }
  }
  Err(())

unless you're keen on having the Ok return at the end of the function. Either way, probably nicer to have a separate let next = ....

@Manishearth
Copy link
Member Author

Manishearth commented Sep 19, 2017 via email

@SimonSapin
Copy link
Member

Lexical lifetimes strike again :)

@bors-servo
Copy link
Contributor

☀️ Test successful - status-travis
Approved by: SimonSapin
Pushing a8edcd9 to master...

@bors-servo bors-servo merged commit 07332bb into servo:master Sep 19, 2017
@Manishearth Manishearth deleted the nth-child-saturate branch September 19, 2017 19:43
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.

4 participants