File tree 2 files changed +18
-3
lines changed
2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 1
1
[package ]
2
2
name = " cssparser"
3
- version = " 0.21.1 "
3
+ version = " 0.21.2 "
4
4
authors = [ " Simon Sapin <simon.sapin@exyr.org>" ]
5
5
6
6
description = " Rust implementation of CSS Syntax Level 3"
Original file line number Diff line number Diff line change 4
4
5
5
use std:: ascii:: AsciiExt ;
6
6
7
- use super :: { Token , Parser , BasicParseError } ;
7
+ use super :: { Token , Parser , ParserInput , BasicParseError } ;
8
8
9
9
10
10
/// Parse the *An+B* notation, as found in the `:nth-child()` selector.
@@ -93,8 +93,23 @@ fn parse_n_dash_digits(string: &str) -> Result<i32, ()> {
93
93
&& string[ ..2 ] . eq_ignore_ascii_case ( "n-" )
94
94
&& string[ 2 ..] . chars ( ) . all ( |c| matches ! ( c, '0' ...'9' ) )
95
95
{
96
- Ok ( string[ 1 ..] . parse ( ) . unwrap ( ) ) // Include the minus sign
96
+ Ok ( parse_number_saturate ( & string[ 1 ..] ) . unwrap ( ) ) // Include the minus sign
97
97
} else {
98
98
Err ( ( ) )
99
99
}
100
100
}
101
+
102
+ fn parse_number_saturate ( string : & str ) -> Result < i32 , ( ) > {
103
+ let mut input = ParserInput :: new ( string) ;
104
+ let mut parser = Parser :: new ( & mut input) ;
105
+ let int = if let Ok ( & Token :: Number { int_value : Some ( int) , ..} )
106
+ = parser. next_including_whitespace_and_comments ( ) {
107
+ int
108
+ } else {
109
+ return Err ( ( ) )
110
+ } ;
111
+ if !parser. is_exhausted ( ) {
112
+ return Err ( ( ) )
113
+ }
114
+ Ok ( int)
115
+ }
You can’t perform that action at this time.
0 commit comments