From cc3e852791801601bdcc7cb8fa1648232c04deb0 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Mon, 10 Mar 2025 11:45:26 +0100 Subject: [PATCH] Treat starting single quote as verbatim text in Slim (#17085) This PR fixes an issue in Slim templates where a single quote `'` at the start of the line (excluding white space) is considered a line indicator for verbatim text. It is not considered a string in this scenario. So something like this: ```slim div 'Foo' ``` Will compile to: ```html
Foo'
``` Fixes: #17081 --- CHANGELOG.md | 1 + .../src/extractor/pre_processors/slim.rs | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b34f6f3e1..e81e71ae5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix `haml` pre-processing ([#17051](https://github.com/tailwindlabs/tailwindcss/pull/17051)) - Ensure classes between `>` and `<` are properly extracted ([#17094](https://github.com/tailwindlabs/tailwindcss/pull/17094)) +- Treat starting single quote as verbatim text in Slim ([#17085](https://github.com/tailwindlabs/tailwindcss/pull/17085)) ## [4.0.12] - 2025-03-07 diff --git a/crates/oxide/src/extractor/pre_processors/slim.rs b/crates/oxide/src/extractor/pre_processors/slim.rs index 8cceb0536..6352a6358 100644 --- a/crates/oxide/src/extractor/pre_processors/slim.rs +++ b/crates/oxide/src/extractor/pre_processors/slim.rs @@ -11,9 +11,26 @@ impl PreProcessor for Slim { let mut result = content.to_vec(); let mut cursor = cursor::Cursor::new(content); let mut bracket_stack = BracketStack::default(); + let mut line_start_pos = 0x00; while cursor.pos < len { match cursor.curr { + b'\n' => { + line_start_pos = cursor.pos + 1; + } + + // Line indicators: + // + // > Verbatim text with trailing white space ' + // > See: https://github.com/slim-template/slim?tab=readme-ov-file#verbatim-text-with-trailing-white-space- + b'\'' + if cursor.input[line_start_pos..cursor.pos] + .iter() + .all(|x| x.is_ascii_whitespace()) => + { + // Do not treat the `'` as a string + } + // Consume strings as-is b'\'' | b'"' => { let len = cursor.input.len(); @@ -154,4 +171,30 @@ mod tests { Slim::test(input, expected); Slim::test_extract_contains(input, vec!["text-black", "bg-green-300", "bg-red-300"]); } + + // https://github.com/tailwindlabs/tailwindcss/issues/17081 + // https://github.com/slim-template/slim?tab=readme-ov-file#verbatim-text-with-trailing-white-space- + #[test] + fn test_single_quotes_to_enforce_trailing_whitespace() { + let input = r#" + div + 'A single quote enforces trailing white space + = 1234 + + .text-red-500.text-3xl + | This text should be red + "#; + + let expected = r#" + div + 'A single quote enforces trailing white space + = 1234 + + text-red-500 text-3xl + | This text should be red + "#; + + Slim::test(input, expected); + Slim::test_extract_contains(input, vec!["text-red-500", "text-3xl"]); + } }