diff options
| author | tjg <tjg> | 2001-10-01 12:54:26 +0000 |
|---|---|---|
| committer | Toby Goodwin <toby@paccrat.org> | 2015-05-16 21:23:19 +0100 |
| commit | 8ce5bc05bcf9b263a65eb6e8d6bae0e610a88b16 (patch) | |
| tree | d1e35e9054b5ab6d82c0c277b80da892782b6033 /lex.c | |
| parent | 593a3857b992c85038276eb0e4c8aa20d796f3de (diff) | |
Bug: it's no longer possible to use parentheses to sneak a word that
needs quoting past the "quoting detector", so `fn x { echo $(x.y) }'
now works both in the current rc and its descendants.
Diffstat (limited to 'lex.c')
| -rw-r--r-- | lex.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -69,6 +69,16 @@ enum filedescriptors { UNSET = -9, CLOSED = -1 }; +/* does this string require quoting? */ +extern bool quotep(char *s) { + unsigned char c; + + while ((c = *s++)) + if (nw[c]) + return TRUE; + return FALSE; +} + extern int yylex() { static bool dollar = FALSE; bool saw_meta = FALSE; @@ -147,6 +157,7 @@ top: while ((c = gchar()) == ' ' || c == '\t') } else { y->word.m = NULL; } + y->word.q = FALSE; return WORD; } if (c == '`' || c == '!' || c == '@' || c == '~' || c == '$' || c == '\'') { @@ -179,7 +190,8 @@ top: while ((c = gchar()) == ' ' || c == '\t') case '\'': w = RW; i = 0; - do { + /* double ' to quote it, like this: 'how''s it going?' */ + while ((c = gchar()) != '\'' || (c = gchar()) == '\'') { buf[i++] = c; if (c == '\n') print_prompt2(); @@ -190,11 +202,12 @@ top: while ((c = gchar()) == ' ' || c == '\t') } if (i >= bufsize) buf = realbuf = erealloc(buf, bufsize *= 2); - } while ((c = gchar()) != '\'' || (c = gchar()) == '\''); /* quote "'" thus: 'how''s it going?' */ + } ugchar(c); buf[i] = '\0'; y->word.w = ncpy(buf); y->word.m = NULL; + y->word.q = TRUE; return WORD; case '\\': if ((c = gchar()) == '\n') { |