summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cmd.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2016-10-21 13:51:59 +0000
committernicm <nicm@openbsd.org>2016-10-21 13:51:59 +0000
commit80774623169e19d3eddfc8d36a7e2d5a263411a8 (patch)
treeb93d6ccdec912e35f242127b14530c0f2c8cc272 /usr.bin/tmux/cmd.c
parentmore tweaks; ok dlg (diff)
downloadwireguard-openbsd-80774623169e19d3eddfc8d36a7e2d5a263411a8.tar.xz
wireguard-openbsd-80774623169e19d3eddfc8d36a7e2d5a263411a8.zip
Add %%% to substitute with quotes escaped (convert " to \"). Use this
for the prompts in copy mode. Fixes problems with jumping to ' reported by Theo Buehler.
Diffstat (limited to 'usr.bin/tmux/cmd.c')
-rw-r--r--usr.bin/tmux/cmd.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/usr.bin/tmux/cmd.c b/usr.bin/tmux/cmd.c
index c2d50f8ed77..32e9c0f67ba 100644
--- a/usr.bin/tmux/cmd.c
+++ b/usr.bin/tmux/cmd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd.c,v 1.126 2016/10/16 19:04:05 nicm Exp $ */
+/* $OpenBSD: cmd.c,v 1.127 2016/10/21 13:51:59 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -653,8 +653,8 @@ char *
cmd_template_replace(const char *template, const char *s, int idx)
{
char ch, *buf;
- const char *ptr;
- int replaced;
+ const char *ptr, *cp;
+ int replaced, quoted;
size_t len;
if (strchr(template, '%') == NULL)
@@ -676,9 +676,17 @@ cmd_template_replace(const char *template, const char *s, int idx)
}
ptr++;
- len += strlen(s);
- buf = xrealloc(buf, len + 1);
- strlcat(buf, s, len + 1);
+ quoted = (*ptr == '%');
+ if (quoted)
+ ptr++;
+
+ buf = xrealloc(buf, len + (strlen(s) * 2) + 1);
+ for (cp = s; *cp != '\0'; cp++) {
+ if (quoted && *cp == '"')
+ buf[len++] = '\\';
+ buf[len++] = *cp;
+ }
+ buf[len] = '\0';
continue;
}
buf = xrealloc(buf, len + 2);