From 0dae22d4383837258f3d226d1db7b46e8d1cb25d Mon Sep 17 00:00:00 2001 From: RobbingDaHood <16130319+RobbingDaHood@users.noreply.github.com> Date: Wed, 18 Dec 2024 09:05:04 +0100 Subject: [PATCH] #10327 Now hashtags get parsed as comment starters if they are prefixed with any whitespace. --- crates/nu-parser/src/lex.rs | 7 +++++-- crates/nu-parser/tests/test_lex.rs | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/nu-parser/src/lex.rs b/crates/nu-parser/src/lex.rs index 6d1adf28ef..b808f6eacc 100644 --- a/crates/nu-parser/src/lex.rs +++ b/crates/nu-parser/src/lex.rs @@ -149,8 +149,11 @@ pub fn lex_item( quote_start = None; } } else if c == b'#' && !in_comment { - // To start a comment, It either need to be the first character of the token or prefixed with space. - in_comment = previous_char.map(|pc| pc == b' ').unwrap_or(true); + // To start a comment, It either need to be the first character of the token or prefixed with whitespace. + in_comment = previous_char + .map(char::from) + .map(char::is_whitespace) + .unwrap_or(true); } else if c == b'\n' || c == b'\r' { in_comment = false; if is_item_terminator(&block_level, c, additional_whitespace, special_tokens) { diff --git a/crates/nu-parser/tests/test_lex.rs b/crates/nu-parser/tests/test_lex.rs index 54ff674bb9..2c1cf85bd8 100644 --- a/crates/nu-parser/tests/test_lex.rs +++ b/crates/nu-parser/tests/test_lex.rs @@ -182,6 +182,20 @@ fn lex_comment_with_space_in_front_of_hashtag() { )); } +#[test] +fn lex_comment_with_tab_in_front_of_hashtag() { + let file = b"1..10 | each {echo test\t#testing }"; + + let output = lex(file, 0, &[], &[], false); + + assert!(output.1.is_some()); + assert!(matches!( + output.1.unwrap(), + ParseError::UnexpectedEof(missing_token, span) if missing_token == "}" + && span == Span::new(33, 34) + )); +} + #[test] fn lex_is_incomplete() { let file = b"let x = 300 | ;";