From 4264efb37d2fad2f40a35dd76f3aaa47c86b634f Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Mon, 26 May 2025 17:53:32 +0200 Subject: [PATCH 1/2] fix Haml crash when there is no `\n` at the end of the file --- .../oxide/src/extractor/pre_processors/haml.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/oxide/src/extractor/pre_processors/haml.rs b/crates/oxide/src/extractor/pre_processors/haml.rs index 810bbb2c35ed..a131618abe66 100644 --- a/crates/oxide/src/extractor/pre_processors/haml.rs +++ b/crates/oxide/src/extractor/pre_processors/haml.rs @@ -330,6 +330,11 @@ impl Haml { cursor.advance(); } + // We didn't find a newline, we reached the end of the input + if last_known_newline_position == last_newline_position { + return cursor.pos; + } + // Move the cursor to the last newline position cursor.move_to(last_newline_position); @@ -446,4 +451,16 @@ mod tests { "#; Haml::test_extract_contains(input, vec!["flex", "items-center"]); } + + // https://github.com/tailwindlabs/tailwindcss/issues/17379#issuecomment-2910108646 + #[test] + fn test_crash_missing_newline() { + // The empty `""` will introduce a newline + let good = ["- index = 0", "- index += 1", ""].join("\n"); + Haml::test_extract_contains(&good, vec!["index"]); + + // This used to crash before the fix + let bad = ["- index = 0", "- index += 1"].join("\n"); + Haml::test_extract_contains(&bad, vec!["index"]); + } } From a81a9b51965bd19b451bc4e6a914b34b5c8c36e2 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Mon, 26 May 2025 18:32:07 +0200 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc14695211ce..7c025a94076a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Support Leptos `class:` attributes when extracting classes ([#18093](https://github.com/tailwindlabs/tailwindcss/pull/18093)) - Fix "Cannot read properties of undefined" crash on malformed arbitrary value ([#18133](https://github.com/tailwindlabs/tailwindcss/pull/18133)) - Upgrade: Migrate `-mt-[0px]` to `mt-[0px]` instead of the other way around ([#18154](https://github.com/tailwindlabs/tailwindcss/pull/18154)) +- Fix Haml pre-processing crash when there is no `\n` at the end of the file ([#18155](https://github.com/tailwindlabs/tailwindcss/pull/18155)) ## [4.1.7] - 2025-05-15