diff options
| author | 2023-01-19 20:28:34 -0800 | |
|---|---|---|
| committer | 2023-01-19 20:28:34 -0800 | |
| commit | 4c0b0e2e8ee3a2710ea3d5b3711efc905f6f2be5 (patch) | |
| tree | 8a559a3eba5b1f6d1f0ece48f1619f1d752a58dc /src | |
| parent | bab7e63d7cf928460c34c8bf438fc167fe5e7b31 (diff) | |
| download | bun-4c0b0e2e8ee3a2710ea3d5b3711efc905f6f2be5.tar.gz bun-4c0b0e2e8ee3a2710ea3d5b3711efc905f6f2be5.tar.zst bun-4c0b0e2e8ee3a2710ea3d5b3711efc905f6f2be5.zip | |
Fix buffer encoding bug
Diffstat (limited to 'src')
| -rw-r--r-- | src/bun.js/node/types.zig | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 79e2c0618..e7f76c018 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -221,6 +221,10 @@ pub const StringOrBuffer = union(Tag) { } pub fn fromJS(global: *JSC.JSGlobalObject, allocator: std.mem.Allocator, value: JSC.JSValue, exception: JSC.C.ExceptionRef) ?StringOrBuffer { + if (!value.isCell()) { + var zig_str = value.toSlice(global, allocator); + return StringOrBuffer{ .string = zig_str.slice() }; + } return switch (value.jsType()) { JSC.JSValue.JSType.String, JSC.JSValue.JSType.StringObject, JSC.JSValue.JSType.DerivedStringObject, JSC.JSValue.JSType.Object => { var zig_str = value.toSlice(global, allocator); @@ -418,7 +422,7 @@ pub const SliceOrBuffer = union(Tag) { } const out = brk: { - if (zig_str.is16Bit()) { + if (!zig_str.is16Bit()) { const buf = zig_str.slice(); break :brk switch (encoding) { Encoding.utf8 => JSC.WebCore.Encoder.constructFromU8(buf.ptr, buf.len, .utf8), |
