diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-06-12 07:10:44 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-06-12 07:10:44 +0000 |
commit | b866915169497bec48392aaed82d82be86858f88 (patch) | |
tree | cdcafef58b30c74a59667c7b73b23b7fb66be537 | |
parent | fb0faff641debbf3148952141e14ee24a3a5b378 (diff) |
Fix quoting with newlines and single quotes.
-rw-r--r-- | usr.bin/tmux/arguments.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/usr.bin/tmux/arguments.c b/usr.bin/tmux/arguments.c index 750fcd3ce55..45ecaaacbaa 100644 --- a/usr.bin/tmux/arguments.c +++ b/usr.bin/tmux/arguments.c @@ -1,4 +1,4 @@ -/* $OpenBSD: arguments.c,v 1.34 2020/06/04 07:12:05 nicm Exp $ */ +/* $OpenBSD: arguments.c,v 1.35 2020/06/12 07:10:43 nicm Exp $ */ /* * Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -212,32 +212,35 @@ args_print(struct args *args) char * args_escape(const char *s) { - static const char quoted[] = " #\"';${}"; + static const char dquoted[] = " #';${}"; + static const char squoted[] = " \""; char *escaped, *result; - int flags; + int flags, quotes = 0; if (*s == '\0') { xasprintf(&result, "''"); return (result); } + if (s[strcspn(s, dquoted)] != '\0') + quotes = '"'; + else if (s[strcspn(s, squoted)] != '\0') + quotes = '\''; + if (s[0] != ' ' && - (strchr(quoted, s[0]) != NULL || s[0] == '~') && - s[1] == '\0') { + s[1] == '\0' && + (quotes != 0 || s[0] == '~')) { xasprintf(&escaped, "\\%c", s[0]); return (escaped); } - if (strchr(s, ' ') != NULL && strchr(s, '\'') == NULL) { - xasprintf(&escaped, "'%s'", s); - return (escaped); - } - flags = VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL; - if (s[strcspn(s, quoted)] != '\0') + if (quotes == '"') flags |= VIS_DQ; utf8_stravis(&escaped, s, flags); - if (flags & VIS_DQ) { + if (quotes == '\'') + xasprintf(&result, "'%s'", escaped); + else if (quotes == '"') { if (*escaped == '~') xasprintf(&result, "\"\\%s\"", escaped); else |