From 6067f7dbe19be82b109142edd017448583b91e1d Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Sun, 1 Oct 2017 18:58:47 +1100 Subject: [PATCH] Avoid boundary check in parse_n_dash_digits --- Cargo.toml | 2 +- src/css-parsing-tests/An+B.json | 4 +++- src/nth.rs | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1cbb2e73..96354cfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cssparser" -version = "0.21.2" +version = "0.21.3" authors = [ "Simon Sapin " ] description = "Rust implementation of CSS Syntax Level 3" diff --git a/src/css-parsing-tests/An+B.json b/src/css-parsing-tests/An+B.json index f17849ea..b1ecf35d 100644 --- a/src/css-parsing-tests/An+B.json +++ b/src/css-parsing-tests/An+B.json @@ -151,6 +151,8 @@ " +n - 1", [1, -1], " -n - 1", [-1, -1], "+ N - 1", null, -"- N - 1", null +"- N - 1", null, + +"2n\u22121", null ] diff --git a/src/nth.rs b/src/nth.rs index ef0adbcd..c9110cda 100644 --- a/src/nth.rs +++ b/src/nth.rs @@ -89,9 +89,10 @@ fn parse_signless_b<'i, 't>(input: &mut Parser<'i, 't>, a: i32, b_sign: i32) -> } fn parse_n_dash_digits(string: &str) -> Result { - if string.len() >= 3 - && string[..2].eq_ignore_ascii_case("n-") - && string[2..].chars().all(|c| matches!(c, '0'...'9')) + let bytes = string.as_bytes(); + if bytes.len() >= 3 + && bytes[..2].eq_ignore_ascii_case(b"n-") + && bytes[2..].iter().all(|&c| matches!(c, b'0'...b'9')) { Ok(parse_number_saturate(&string[1..]).unwrap()) // Include the minus sign } else {