Browse Source

fix escapes handling (patch from ac)

Quentin Carbonneaux 9 years ago
parent
commit
ea4b47003b
1 changed files with 4 additions and 3 deletions
  1. 4 3
      parse.c

+ 4 - 3
parse.c

@@ -202,7 +202,7 @@ lex()
 		{ 0, Txxx }
 		{ 0, Txxx }
 	};
 	};
 	static char tok[NString];
 	static char tok[NString];
-	int c, i;
+	int c, i, esc;
 	int t;
 	int t;
 
 
 	do
 	do
@@ -262,16 +262,17 @@ lex()
 	}
 	}
 	if (c == '"') {
 	if (c == '"') {
 		tokval.str = vnew(0, 1, alloc);
 		tokval.str = vnew(0, 1, alloc);
+		esc = 0;
 		for (i=0;; i++) {
 		for (i=0;; i++) {
 			c = fgetc(inf);
 			c = fgetc(inf);
 			if (c == EOF)
 			if (c == EOF)
 				err("unterminated string");
 				err("unterminated string");
 			vgrow(&tokval.str, i+1);
 			vgrow(&tokval.str, i+1);
-			if (c == '"')
-			if (!i || tokval.str[i-1] != '\\') {
+			if (c == '"' && !esc) {
 				tokval.str[i] = 0;
 				tokval.str[i] = 0;
 				return Tstr;
 				return Tstr;
 			}
 			}
+			esc = (c == '\\' && !esc);
 			tokval.str[i] = c;
 			tokval.str[i] = c;
 		}
 		}
 	}
 	}