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

This commit is contained in:
IoIxD 2026-01-21 14:21:25 -07:00
commit 8d8db38576

View file

@ -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;
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) {