File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 11[package ]
22name = " cssparser"
3- version = " 0.21.1 "
3+ version = " 0.21.2 "
44authors = [ " Simon Sapin <simon.sapin@exyr.org>" ]
55
66description = " Rust implementation of CSS Syntax Level 3"
Original file line number Diff line number Diff line change 44
55use std:: ascii:: AsciiExt ;
66
7- use super :: { Token , Parser , BasicParseError } ;
7+ use super :: { Token , Parser , ParserInput , BasicParseError } ;
88
99
1010/// 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, ()> {
9393 && string[ ..2 ] . eq_ignore_ascii_case ( "n-" )
9494 && string[ 2 ..] . chars ( ) . all ( |c| matches ! ( c, '0' ...'9' ) )
9595 {
96- Ok ( string[ 1 ..] . parse ( ) . unwrap ( ) ) // Include the minus sign
96+ Ok ( parse_number_saturate ( & string[ 1 ..] ) . unwrap ( ) ) // Include the minus sign
9797 } else {
9898 Err ( ( ) )
9999 }
100100}
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