Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix Haml crash when there is no \n at the end of the file
  • Loading branch information
RobinMalfait committed May 26, 2025
commit 4264efb37d2fad2f40a35dd76f3aaa47c86b634f
17 changes: 17 additions & 0 deletions crates/oxide/src/extractor/pre_processors/haml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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"]);
}
}