summaryrefslogtreecommitdiffstats
path: root/format.c
diff options
context:
space:
mode:
authornicm <nicm>2022-11-04 08:03:23 +0000
committernicm <nicm>2022-11-04 08:03:23 +0000
commit77c135349aaaa026c3fbb24d291877ce926d682e (patch)
treec33e92dc413c02afef5d456ec7215af6a9cc7f0a /format.c
parent17290b912116c4397620526d43dcf6ddcf0044b7 (diff)
Unescape the string for the literal operator (l:) so special characters
work.
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 535af061..5b08a7a4 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;
}