From be82047dbf5f74f123e925b96e0e13962a4e0c09 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 28 Oct 2024 12:21:09 +1100 Subject: Only check for ascii horizontal blanks during command parsing The general is_horizontal_blank supports various unicode blanks, but passing an utf8 continuation byte to it can lead to surprising results as we can match with 0xA0 (when char is unsigned). Fixes #5250 --- src/command_manager.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/command_manager.cc') diff --git a/src/command_manager.cc b/src/command_manager.cc index e30f8a68..0db97e94 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -179,6 +179,13 @@ ParseResult parse_quoted_balanced(ParseState& state) return {String{String::NoCopy{}, {beg, pos - terminated}}, terminated}; } +bool is_ascii_horizontal_blank(char c) +{ + return c == '\t' or + c == '\f' or + c == ' '; +} + String parse_unquoted(ParseState& state) { const char* beg = state.pos; @@ -189,7 +196,7 @@ String parse_unquoted(ParseState& state) while (state.pos != end) { const char c = *state.pos; - if (is_command_separator(c) or is_horizontal_blank(c)) + if (is_command_separator(c) or is_ascii_horizontal_blank(c)) { str += StringView{beg, state.pos}; if (state.pos != beg and *(state.pos - 1) == '\\') @@ -235,8 +242,8 @@ void skip_blanks_and_comments(ParseState& state) { while (state) { - const Codepoint c = *state.pos; - if (is_horizontal_blank(c)) + const char c = *state.pos; + if (is_ascii_horizontal_blank(c)) ++state.pos; else if (c == '\\' and state.pos + 1 != state.str.end() and state.pos[1] == '\n') -- cgit v1.2.3