changeset 22799:d92381842a4f

lib: var-expand - handle \{ and \} correctly Do not treat these as embedded braces
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Fri, 01 Dec 2017 19:46:58 +0200
parents 30265531b608
children 58f41eb48676
files src/lib/var-expand.c
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/var-expand.c	Fri Dec 01 14:53:46 2017 +0200
+++ b/src/lib/var-expand.c	Fri Dec 01 19:46:58 2017 +0200
@@ -544,8 +544,17 @@
 				/* %{long_key} */
 				const char *error;
 				unsigned int ctr = 1;
+				bool escape = FALSE;
 				end = str;
 				while(*++end != '\0' && ctr > 0) {
+					if (!escape && *end == '\\') {
+						escape = TRUE;
+						continue;
+					}
+					if (escape) {
+						escape = FALSE;
+						continue;
+					}
 					if (*end == '{') ctr++;
 					if (*end == '}') ctr--;
 				}
@@ -644,6 +653,14 @@
 		/* long key */
 		*idx_r = ++i;
 		for (; str[i] != '\0'; i++) {
+			if (!escape && str[i] == '\\') {
+				escape = TRUE;
+				continue;
+			}
+			if (escape) {
+				escape = FALSE;
+				continue;
+			}
 			if (str[i] == '{')
 				depth++;
 			if (str[i] == '}') {