From 8ce5bc05bcf9b263a65eb6e8d6bae0e610a88b16 Mon Sep 17 00:00:00 2001 From: tjg Date: Mon, 1 Oct 2001 12:54:26 +0000 Subject: 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. --- lex.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'lex.c') diff --git a/lex.c b/lex.c index 7e35cdd..45b6ddb 100644 --- a/lex.c +++ b/lex.c @@ -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') { -- cgit v1.2.3