From 3906e4066d3873619603f3a662bb09e8f754e6d1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 11 Apr 2019 07:25:27 -0700 Subject: [PATCH] Fix a bug using `encodeInto` truncating strings The last write accidentally wasn't accounted for in the returned length of the string and we unfortunately don't have any test coverage of `encodeInto` since it requires Firefox nightly right now (and doesn't work in Node yet). Closes #1436 --- crates/cli-support/src/js/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index b1896fd44f2..d9f02ad6c03 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -1364,11 +1364,11 @@ impl<'a> Context<'a> { while (true) {{ const view = getUint8Memory().subarray(ptr + writeOffset, ptr + size); const {{ read, written }} = cachedTextEncoder.encodeInto(arg, view); + writeOffset += written; if (read === arg.length) {{ break; }} arg = arg.substring(read); - writeOffset += written; ptr = wasm.__wbindgen_realloc(ptr, size, size += arg.length * 3); }} WASM_VECTOR_LEN = writeOffset;