فهرست منبع

support backslash-escaping in the config file

note that no attempt is made at making this work in the compat wrapper.
Oswald Buddenhagen 11 سال پیش
والد
کامیت
17c4748dfa
2فایلهای تغییر یافته به همراه15 افزوده شده و 4 حذف شده
  1. 13 3
      src/config.c
  2. 2 1
      src/mbsync.1

+ 13 - 3
src/config.c

@@ -48,7 +48,7 @@ static char *
 get_arg( conffile_t *cfile, int required, int *comment )
 {
 	char *ret, *p, *t;
-	int quoted;
+	int escaped, quoted;
 	char c;
 
 	p = cfile->rest;
@@ -64,9 +64,14 @@ get_arg( conffile_t *cfile, int required, int *comment )
 		}
 		ret = 0;
 	} else {
-		for (quoted = 0, ret = t = p; c; c = *p) {
+		for (escaped = 0, quoted = 0, ret = t = p; c; c = *p) {
 			p++;
-			if (c == '"')
+			if (escaped && c >= 32) {
+				escaped = 0;
+				*t++ = c;
+			} else if (c == '\\')
+				escaped = 1;
+			else if (c == '"')
 				quoted ^= 1;
 			else if (!quoted && isspace( (unsigned char) c ))
 				break;
@@ -74,6 +79,11 @@ get_arg( conffile_t *cfile, int required, int *comment )
 				*t++ = c;
 		}
 		*t = 0;
+		if (escaped) {
+			error( "%s:%d: unterminated escape sequence\n", cfile->file, cfile->line );
+			cfile->err = 1;
+			ret = 0;
+		}
 		if (quoted) {
 			error( "%s:%d: missing closing quote\n", cfile->file, cfile->line );
 			cfile->err = 1;

+ 2 - 1
src/mbsync.1

@@ -88,7 +88,8 @@ If specified twice, suppress warning messages as well.
 The configuration file is mandatory; \fBmbsync\fR will not run without it.
 Lines starting with a hash mark (\fB#\fR) are comments and are ignored entirely.
 Configuration items are keywords followed by one or more arguments;
-arguments containing spaces must be enclosed in double quotes (\fB"\fR).
+arguments containing spaces must be enclosed in double quotes (\fB"\fR),
+and literal double quotes and backslashes (\fB\\\fR) must be backslash-escaped.
 All keywords (including those used as arguments) are case-insensitive.
 Bash-like home directory expansion using the tilde (\fB~\fR) is supported
 in all options which represent local paths.