summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2022-11-04 08:03:24 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2022-11-04 08:03:24 +0000
commit28e2ce9fd0de14b39493bdd1dbed33194d403930 (patch)
tree72d0e54bae3e0e2849edd7ef02e244dbfe0a34c9 /usr.bin/tmux
parente03883c9aace02589f4bb812d30898f54e217399 (diff)
Unescape the string for the literal operator (l:) so special characters
work.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/format.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index 1e5eaf18f8c..8234fdf9a73 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.309 2022/07/19 06:46:57 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.310 2022/11/04 08:03:23 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -3575,7 +3575,32 @@ found:
return (found);
}
-/* Remove escaped characters from string. */
+/* Unescape escaped characters. */
+static char *
+format_unescape(const char *s)
+{
+ char *out, *cp;
+ int brackets = 0;
+
+ cp = out = xmalloc(strlen(s) + 1);
+ for (; *s != '\0'; s++) {
+ if (*s == '#' && s[1] == '{')
+ brackets++;
+ if (brackets == 0 &&
+ *s == '#' &&
+ strchr(",#{}:", s[1]) != NULL) {
+ *cp++ = *++s;
+ continue;
+ }
+ if (*s == '}')
+ brackets--;
+ *cp++ = *s;
+ }
+ *cp = '\0';
+ return (out);
+}
+
+/* Remove escaped characters. */
static char *
format_strip(const char *s)
{
@@ -4338,7 +4363,8 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
/* Is this a literal string? */
if (modifiers & FORMAT_LITERAL) {
- value = xstrdup(copy);
+ format_log(es, "literal string is '%s'", copy);
+ value = format_unescape(copy);
goto done;
}