Skip to content

Commit 6067f7d

Browse files
committed
Avoid boundary check in parse_n_dash_digits
1 parent bd213ed commit 6067f7d

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cssparser"
3-
version = "0.21.2"
3+
version = "0.21.3"
44
authors = [ "Simon Sapin <simon.sapin@exyr.org>" ]
55

66
description = "Rust implementation of CSS Syntax Level 3"

src/css-parsing-tests/An+B.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@
151151
" +n - 1", [1, -1],
152152
" -n - 1", [-1, -1],
153153
"+ N - 1", null,
154-
"- N - 1", null
154+
"- N - 1", null,
155+
156+
"2n\u22121", null
155157

156158
]

src/nth.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ fn parse_signless_b<'i, 't>(input: &mut Parser<'i, 't>, a: i32, b_sign: i32) ->
8989
}
9090

9191
fn parse_n_dash_digits(string: &str) -> Result<i32, ()> {
92-
if string.len() >= 3
93-
&& string[..2].eq_ignore_ascii_case("n-")
94-
&& string[2..].chars().all(|c| matches!(c, '0'...'9'))
92+
let bytes = string.as_bytes();
93+
if bytes.len() >= 3
94+
&& bytes[..2].eq_ignore_ascii_case(b"n-")
95+
&& bytes[2..].iter().all(|&c| matches!(c, b'0'...b'9'))
9596
{
9697
Ok(parse_number_saturate(&string[1..]).unwrap()) // Include the minus sign
9798
} else {

0 commit comments

Comments
 (0)