Browse Source

[eval] fix StringBuf.addSub unicode handling

closes #9382
Simon Krajewski 5 years ago
parent
commit
3d600a0cfb
2 changed files with 11 additions and 1 deletions
  1. 1 1
      src/macro/eval/evalStdLib.ml
  2. 10 0
      tests/unit/src/unit/issues/Issue9382.hx

+ 1 - 1
src/macro/eval/evalStdLib.ml

@@ -2395,7 +2395,7 @@ module StdStringBuf = struct
 		let s = decode_vstring s in
 		let s = decode_vstring s in
 		let c_pos = decode_int pos in
 		let c_pos = decode_int pos in
 		let c_len = match len with
 		let c_len = match len with
-			| VNull -> String.length s.sstring - c_pos
+			| VNull -> s.slength - c_pos
 			| VInt32 i -> Int32.to_int i
 			| VInt32 i -> Int32.to_int i
 			| _ -> unexpected_value len "int"
 			| _ -> unexpected_value len "int"
 		in
 		in

+ 10 - 0
tests/unit/src/unit/issues/Issue9382.hx

@@ -0,0 +1,10 @@
+package unit.issues;
+
+class Issue9382 extends unit.Test {
+
+	function test() {
+		var buf = new StringBuf();
+		buf.addSub('🦖', 0);
+		eq('🦖', buf.toString());
+	}
+}