aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-03-07 22:59:29 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-03-07 22:59:29 -0800
commite16053c39ed18fb7024159d7e8bc58e5120bbf34 (patch)
tree4316ee6b1bdf947dfd7d867f806d2a108179e8a3
parente389b6ef1985ffe54ecae212891e85013ece8ac0 (diff)
downloadbun-e16053c39ed18fb7024159d7e8bc58e5120bbf34.tar.gz
bun-e16053c39ed18fb7024159d7e8bc58e5120bbf34.tar.zst
bun-e16053c39ed18fb7024159d7e8bc58e5120bbf34.zip
"binary" is an alias of "latin1"
Fixes https://github.com/oven-sh/bun/issues/2110
-rw-r--r--src/bun.js/node/types.zig7
-rw-r--r--test/js/node/crypto/node-crypto.test.js6
2 files changed, 11 insertions, 2 deletions
diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig
index b70ad9ea3..6bee1243f 100644
--- a/src/bun.js/node/types.zig
+++ b/src/bun.js/node/types.zig
@@ -374,7 +374,7 @@ pub const SliceOrBuffer = union(Tag) {
}
const encoding: Encoding = brk: {
- if (encoding_value.isEmpty())
+ if (encoding_value.isEmptyOrUndefinedOrNull())
break :brk .utf8;
var encoding_str = encoding_value.toSlice(global, allocator);
if (encoding_str.len == 0)
@@ -442,7 +442,10 @@ pub const Encoding = enum(u8) {
Eight.case("utf-8"), Eight.case("utf8") => Encoding.utf8,
Eight.case("ucs-2"), Eight.case("ucs2") => Encoding.ucs2,
Eight.case("utf16-le"), Eight.case("utf16le") => Encoding.utf16le,
- Eight.case("latin1") => Encoding.latin1,
+
+ // "binary" is an alias for "latin1"
+ Eight.case("binary"), Eight.case("latin1") => Encoding.latin1,
+
Eight.case("ascii") => Encoding.ascii,
Eight.case("base64") => Encoding.base64,
Eight.case("hex") => Encoding.hex,
diff --git a/test/js/node/crypto/node-crypto.test.js b/test/js/node/crypto/node-crypto.test.js
index f148f4fe9..324a2790f 100644
--- a/test/js/node/crypto/node-crypto.test.js
+++ b/test/js/node/crypto/node-crypto.test.js
@@ -27,3 +27,9 @@ it("web crypto", async () => {
crypto.getRandomValues(bytes);
await crypto.subtle.digest("SHA-256", bytes);
});
+
+// https://github.com/oven-sh/bun/issues/2110
+it("hash regression #2110", () => {
+ var s = "6fbf7e2948e0c2f29eaacac1733546a4af5ca482";
+ expect(crypto.createHash("sha1").update(s, "binary").digest("hex")).toBe("e7c8b3c6f114c523d07ee355c534ee9bef3c044b");
+});