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:
parent
20c9b01967
commit
8d8db38576
1 changed files with 11 additions and 3 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue