From 8d8db3857665f44da245971ed98fea0cb0dddbf4 Mon Sep 17 00:00:00 2001 From: IoIxD Date: Wed, 21 Jan 2026 14:21:25 -0700 Subject: [PATCH] don't add quotes to the command when we use them, support escaping them, and don't support using single quotes in place of them --- src/lexer/lexer.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index 5521191..0caa2e2 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -80,6 +80,7 @@ void msh_lexer_parse(msh_lexer *lexer, char *buf, SIZE_TYPE sz) { break; */ + int escaping = 0; int quote_mode = 0; for (i = 0; i < sz; i++) { @@ -89,10 +90,16 @@ void msh_lexer_parse(msh_lexer *lexer, char *buf, SIZE_TYPE sz) { cur_word_buf[n++] = '\0'; msh_lexer_push_item(lexer, MSH_LEXER_ITEM_TYPE_WORD, cur_word_buf, n); goto lexer_cancel; + case '\\': + escaping = 1; + break; case '"': - case '\'': - quote_mode = !quote_mode; - goto do_add; + if (escaping) { + goto do_add; + } else { + quote_mode = !quote_mode; + } + break; case ' ': if (quote_mode == 1) { goto do_add; @@ -107,6 +114,7 @@ void msh_lexer_parse(msh_lexer *lexer, char *buf, SIZE_TYPE sz) { default: do_add: cur_word_buf[n++] = buf[i]; + escaping = 0; break; } if (do_clear) {