mirror of
https://github.com/tmux/tmux.git
synced 2026-06-20 17:25:57 +00:00
Unescape arguments before passing to format_expand1 so that escaping :s
etc actually works.
This commit is contained in:
22
format.c
22
format.c
@@ -4240,22 +4240,24 @@ format_check_time(struct format_expand_state *es, u_int *check)
|
|||||||
|
|
||||||
/* Unescape escaped characters. */
|
/* Unescape escaped characters. */
|
||||||
static char *
|
static char *
|
||||||
format_unescape(struct format_expand_state *es, const char *s)
|
format_unescape(struct format_expand_state *es, const char *s, size_t n)
|
||||||
{
|
{
|
||||||
char *out, *cp;
|
const char *end = s + n;
|
||||||
int brackets = 0;
|
char *out, *cp;
|
||||||
u_int check = 0;
|
int brackets = 0;
|
||||||
|
u_int check = 0;
|
||||||
|
|
||||||
cp = out = xmalloc(strlen(s) + 1);
|
cp = out = xmalloc(n + 1);
|
||||||
for (; *s != '\0'; s++) {
|
for (; s != end; s++) {
|
||||||
if (!format_check_time(es, &check)) {
|
if (!format_check_time(es, &check)) {
|
||||||
free(out);
|
free(out);
|
||||||
return (xstrdup(""));
|
return (xstrdup(""));
|
||||||
}
|
}
|
||||||
if (*s == '#' && s[1] == '{')
|
if (*s == '#' && s + 1 != end && s[1] == '{')
|
||||||
brackets++;
|
brackets++;
|
||||||
if (brackets == 0 &&
|
if (brackets == 0 &&
|
||||||
*s == '#' &&
|
*s == '#' &&
|
||||||
|
s + 1 != end &&
|
||||||
strchr(",#{}:", s[1]) != NULL) {
|
strchr(",#{}:", s[1]) != NULL) {
|
||||||
*cp++ = *++s;
|
*cp++ = *++s;
|
||||||
continue;
|
continue;
|
||||||
@@ -4476,7 +4478,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
argv = xcalloc(1, sizeof *argv);
|
argv = xcalloc(1, sizeof *argv);
|
||||||
value = xstrndup(cp + 1, end - (cp + 1));
|
value = format_unescape(es, cp + 1, end - (cp + 1));
|
||||||
argv[0] = format_expand1(es, value);
|
argv[0] = format_expand1(es, value);
|
||||||
free(value);
|
free(value);
|
||||||
argc = 1;
|
argc = 1;
|
||||||
@@ -4500,7 +4502,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
|||||||
cp++;
|
cp++;
|
||||||
|
|
||||||
argv = xreallocarray(argv, argc + 1, sizeof *argv);
|
argv = xreallocarray(argv, argc + 1, sizeof *argv);
|
||||||
value = xstrndup(cp, end - cp);
|
value = format_unescape(es, cp, end - cp);
|
||||||
argv[argc++] = format_expand1(es, value);
|
argv[argc++] = format_expand1(es, value);
|
||||||
free(value);
|
free(value);
|
||||||
|
|
||||||
@@ -5368,7 +5370,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
/* Is this a literal string? */
|
/* Is this a literal string? */
|
||||||
if (modifiers & FORMAT_LITERAL) {
|
if (modifiers & FORMAT_LITERAL) {
|
||||||
format_log(es, "literal string is '%s'", copy);
|
format_log(es, "literal string is '%s'", copy);
|
||||||
value = format_unescape(es, copy);
|
value = format_unescape(es, copy, strlen(copy));
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user