2
0
Эх сурвалжийг харах

Disallow UTF-16 surrogates in strings (#8208)

Aurel 6 жил өмнө
parent
commit
9769f0bc1c

+ 2 - 0
src/core/ast.ml

@@ -524,6 +524,8 @@ let unescape s =
 							| Invalid_escape_sequence (c,i,msg) as e -> raise e
 							| _ -> fail_no_hex ()
 					in
+					if u >= 0xD800 && u < 0xE000 then
+						fail (Some "UTF-16 surrogates are not allowed in strings.");
 					UTF8.add_uchar b (UChar.uchar_of_int u);
 					inext := !inext + a;
 				| _ ->

+ 6 - 0
tests/misc/projects/Issue8205/Main.hx

@@ -0,0 +1,6 @@
+class Main {
+	static function main() {
+		trace("\u{1F404}");
+		trace("\uD83D\uDC04");
+	}
+}

+ 2 - 0
tests/misc/projects/Issue8205/compile-fail.hxml

@@ -0,0 +1,2 @@
+--main Main
+--interp

+ 1 - 0
tests/misc/projects/Issue8205/compile-fail.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:4: character 10 : Invalid escape sequence \u. UTF-16 surrogates are not allowed in strings.