summaryrefslogtreecommitdiff
path: root/lex.c
diff options
context:
space:
mode:
authortjg <tjg>2001-10-01 12:54:26 +0000
committerToby Goodwin <toby@paccrat.org>2015-05-16 21:23:19 +0100
commit8ce5bc05bcf9b263a65eb6e8d6bae0e610a88b16 (patch)
treed1e35e9054b5ab6d82c0c277b80da892782b6033 /lex.c
parent593a3857b992c85038276eb0e4c8aa20d796f3de (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.c17
1 files changed, 15 insertions, 2 deletions
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') {