Sfoglia il codice sorgente

Limit octal string escapes to ASCII range as well (#8469)

* limit octal string escapes to ASCII range as well

* don't break silently

* test

* fix test
Aurel 6 anni fa
parent
commit
c7d46f8431

+ 5 - 3
src/core/ast.ml

@@ -497,8 +497,10 @@ let unescape s =
 				| 't' -> Buffer.add_char b '\t'
 				| '"' | '\'' | '\\' -> Buffer.add_char b c
 				| '0'..'3' ->
-					let c = (try char_of_int (int_of_string ("0o" ^ String.sub s i 3)) with _ -> fail None) in
-					Buffer.add_char b c;
+					let u = (try (int_of_string ("0o" ^ String.sub s i 3)) with _ -> fail None) in
+					if u > 127 then
+						fail (Some ("Values greater than \\177 are not allowed. Use \\u00" ^ (Printf.sprintf "%02x" u) ^ " instead."));
+					Buffer.add_char b (char_of_int u);
 					inext := !inext + 2;
 				| 'x' ->
 					let fail_no_hex () = fail (Some "Must be followed by a hexadecimal sequence.") in
@@ -506,7 +508,7 @@ let unescape s =
 					let u = (try (int_of_string ("0x" ^ hex)) with _ -> fail_no_hex ()) in
 					if u > 127 then
 						fail (Some ("Values greater than \\x7f are not allowed. Use \\u00" ^ hex ^ " instead."));
-					UTF8.add_uchar b (UChar.uchar_of_int u);
+					Buffer.add_char b (char_of_int u);
 					inext := !inext + 2;
 				| 'u' ->
 					let fail_no_hex () = fail (Some "Must be followed by a hexadecimal sequence enclosed in curly brackets.") in

+ 5 - 0
tests/misc/projects/Issue8119/Main2.hx

@@ -0,0 +1,5 @@
+class Main2 {
+	static public function main() {
+		"\200";
+	}
+}

+ 1 - 0
tests/misc/projects/Issue8119/compile2-fail.hxml

@@ -0,0 +1 @@
+-main Main2

+ 1 - 0
tests/misc/projects/Issue8119/compile2-fail.hxml.stderr

@@ -0,0 +1 @@
+Main2.hx:3: character 4 : Invalid escape sequence \2. Values greater than \177 are not allowed. Use \u0080 instead.