From 619244b4b13285104e0c554da748a0cc5360fd88 Mon Sep 17 00:00:00 2001 From: inottn Date: Mon, 11 Nov 2024 14:57:17 +0800 Subject: [PATCH] fix: correctly consume escape for consume string token (#2) fix: correctly consume escape for consume string token (#2) --------- Co-authored-by: ahabhgk --- src/lexer.rs | 9 ++++----- tests/test.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/lexer.rs b/src/lexer.rs index 39ed7b0..b444164 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -353,11 +353,9 @@ impl<'s> Lexer<'s> { if c == end { self.consume(); break; - } - if is_new_line(c) { + } else if is_new_line(c) { break; - } - if c == C_REVERSE_SOLIDUS { + } else if c == C_REVERSE_SOLIDUS { self.consume(); let c2 = self.cur()?; if is_new_line(c2) { @@ -365,8 +363,9 @@ impl<'s> Lexer<'s> { } else if are_valid_escape(c, c2) { self.consume_escaped()?; } + } else { + self.consume(); } - self.consume(); } visitor.string(self, start, self.cur_pos()?) } diff --git a/tests/test.rs b/tests/test.rs index f84b150..d8ec46a 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -358,6 +358,34 @@ fn url_2() { ); } +#[test] +fn url_3() { + let input = r#"body{content: "\f101";background-image:url(./img.png)}"#; + let (dependencies, warnings) = collect_dependencies(input, Mode::Css); + assert!(warnings.is_empty()); + assert_url_dependency( + input, + &dependencies[0], + "./img.png", + UrlRangeKind::Function, + "url(./img.png)", + ); +} + +#[test] +fn url_4() { + let input = r#"body{content: "\f\"101";background-image:url(./img.png)}"#; + let (dependencies, warnings) = collect_dependencies(input, Mode::Css); + assert!(warnings.is_empty()); + assert_url_dependency( + input, + &dependencies[0], + "./img.png", + UrlRangeKind::Function, + "url(./img.png)", + ); +} + #[test] fn duplicate_url() { let input = indoc! {r#"