Skip to content

Commit

Permalink
fix: correctly consume escape for consume string token (#2)
Browse files Browse the repository at this point in the history
fix: correctly consume escape for consume string token (#2)

---------

Co-authored-by: ahabhgk <[email protected]>
  • Loading branch information
inottn and ahabhgk authored Nov 11, 2024
1 parent 88abe44 commit 619244b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,20 +353,19 @@ 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) {
self.consume();
} else if are_valid_escape(c, c2) {
self.consume_escaped()?;
}
} else {
self.consume();
}
self.consume();
}
visitor.string(self, start, self.cur_pos()?)
}
Expand Down
28 changes: 28 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"
Expand Down

0 comments on commit 619244b

Please sign in to comment.