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 | ;";