summaryrefslogtreecommitdiffstats
path: root/format.c
diff options
context:
space:
mode:
authornicm <nicm>2022-06-27 09:14:49 +0000
committernicm <nicm>2022-06-27 09:14:49 +0000
commit786cff8db9dd64ec8143a492c63051582ee41288 (patch)
treeb3eccd919b43b61b25e0fa6f00a92bfebca269dc /format.c
parent9c89f7c2af748858e784e8c533c548460bd6b10e (diff)
Do not expand single character format aliases inside #[] since they
interfere with colours. GitHub issue 3239 from Magnus Gross.
Diffstat (limited to 'format.c')
-rw-r--r--format.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/format.c b/format.c
index 69d8ef34..e10f324f 100644
--- a/format.c
+++ b/format.c
@@ -4606,7 +4606,7 @@ format_expand1(struct format_expand_state *es, const char *fmt)
{
struct format_tree *ft = es->ft;
char *buf, *out, *name;
- const char *ptr, *s;
+ const char *ptr, *s, *style_end = NULL;
size_t off, len, n, outlen;
int ch, brackets;
char expanded[8192];
@@ -4701,13 +4701,14 @@ format_expand1(struct format_expand_state *es, const char *fmt)
break;
fmt += n + 1;
continue;
+ case '[':
case '#':
/*
* If ##[ (with two or more #s), then it is a style and
* can be left for format_draw to handle.
*/
- ptr = fmt;
- n = 2;
+ ptr = fmt - (ch == '[');
+ n = 2 - (ch == '[');
while (*ptr == '#') {
ptr++;
n++;
@@ -4721,6 +4722,7 @@ format_expand1(struct format_expand_state *es, const char *fmt)
memcpy(buf + off, fmt - 2, n + 1);
off += n + 1;
fmt = ptr + 1;
+ style_end = format_skip(fmt - 2, "]");
continue;
}
/* FALLTHROUGH */
@@ -4735,10 +4737,12 @@ format_expand1(struct format_expand_state *es, const char *fmt)
continue;
default:
s = NULL;
- if (ch >= 'A' && ch <= 'Z')
- s = format_upper[ch - 'A'];
- else if (ch >= 'a' && ch <= 'z')
- s = format_lower[ch - 'a'];
+ if (fmt > style_end) { /* skip inside #[] */
+ if (ch >= 'A' && ch <= 'Z')
+ s = format_upper[ch - 'A'];
+ else if (ch >= 'a' && ch <= 'z')
+ s = format_lower[ch - 'a'];
+ }
if (s == NULL) {
while (len - off < 3) {
buf = xreallocarray(buf, 2, len);