summaryrefslogtreecommitdiffstats
path: root/format.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2022-11-04 10:01:10 +0000
committerThomas Adam <thomas@xteddy.org>2022-11-04 10:01:10 +0000
commit50f4e0fac93799da5b172bed51ca7e4a61ad7ed4 (patch)
tree929a59f63938f4e051a1e63ae759dd9be1b828f0 /format.c
parentc449512be41f0d4442bc0f2a7cd652c9784423b8 (diff)
parent77c135349aaaa026c3fbb24d291877ce926d682e (diff)
Merge branch 'obsd-master'
Diffstat (limited to 'format.c')
-rw-r--r--format.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/format.c b/format.c
index 8041f728..ee6930b0 100644
--- a/format.c
+++ b/format.c
@@ -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;
}