-
Notifications
You must be signed in to change notification settings - Fork 136
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
Conversation
@bors-servo r+ |
📌 Commit 07332bb has been approved by |
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 -->
There was a problem hiding this 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), ..}) |
There was a problem hiding this comment.
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 = ...
.
Can't check is_exhausted whilst the parser is mutably borrowed by the token
|
Lexical lifetimes strike again :) |
☀️ Test successful - status-travis |
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