Don’t detect arbitrary properties when preceded by an escape (#15456)

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 <malfait.robin@gmail.com>
This commit is contained in:
Jordan PittmanandRobin Malfait authored and GitHub committed 2024-12-20 15:22:49 +01:00
1 parent 34340e3b82
commit 00ccbdc937
2 files changed
+16 -1

No files matched your search

+1
View File
@@ -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
+15 -1
View File
@@ -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,
@@ -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"]);
}
}