Przeglądaj źródła

[js] escape quoted fields in object declarations (closes #5000)

Dan Korostelev 9 lat temu
rodzic
commit
206baecda3

+ 1 - 1
src/generators/genjs.ml

@@ -631,7 +631,7 @@ and gen_expr ctx e =
 	| TObjectDecl fields ->
 		spr ctx "{ ";
 		concat ctx ", " (fun (f,e) -> (match e.eexpr with
-			| TMeta((Meta.QuotedField,_,_),e) -> print ctx "'%s' : " f;
+			| TMeta((Meta.QuotedField,_,_),e) -> print ctx "'%s' : " (Ast.s_escape f);
 			| _ -> print ctx "%s : " (anon_field f));
 			gen_value ctx e
 		) fields;

+ 8 - 0
tests/unit/src/unit/issues/Issue5000.hx

@@ -0,0 +1,8 @@
+package unit.issues;
+
+class Issue5000 extends Test {
+    function test() {
+        var a = {"a\n b": 1};
+        eq(1, Reflect.field(a, "a\n b"));
+    }
+}