Skip to content

Commit

Permalink
Don’t detect arbitrary properties when preceded by an escape (#15456)
Browse files Browse the repository at this point in the history
This is a targeted bug fix uncovered by the v4 docs.

Given this code:
```html
<!-- [!code word:group-has-\\[a\\]\\:block] -->
```

We'd pick up `[a\\]\\:block]` as a candidate which would then make it
far enough to get output to CSS and throw an error. This makes sure we
don't try to start an arbitrary property if the preceding character is a
`\`

cc @RobinMalfait this look okay?

---------

Co-authored-by: Robin Malfait <[email protected]>
  • Loading branch information
thecrypticace and RobinMalfait authored Dec 20, 2024
1 parent 34340e3 commit 00ccbdc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Use the correct property value for `place-content-between`, `place-content-around`, and `place-content-evenly` utilities ([#15440](https://github.com/tailwindlabs/tailwindcss/pull/15440))
- Don’t detect arbitrary properties when preceded by an escape ([#15456](https://github.com/tailwindlabs/tailwindcss/pull/15456))

### Changed

Expand Down
16 changes: 15 additions & 1 deletion crates/oxide/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ impl<'a> Extractor<'a> {
fn parse_start(&mut self) -> ParseAction<'a> {
match self.cursor.curr {
// Enter arbitrary property mode
b'[' => {
b'[' if self.cursor.prev != b'\\' => {
trace!("Arbitrary::Start\t");
self.arbitrary = Arbitrary::Brackets {
start_idx: self.cursor.pos,
Expand Down Expand Up @@ -1634,4 +1634,18 @@ mod test {
]
);
}

#[test]
fn arbitrary_properties_are_not_picked_up_after_an_escape() {
_please_trace();
let candidates = run(
r#"
<!-- [!code word:group-has-\\[a\\]\\:block] -->
\\[a\\]\\:block]
"#,
false,
);

assert_eq!(candidates, vec!["!code", "a"]);
}
}

0 comments on commit 00ccbdc

Please sign in to comment.