From 565d1689e9f2c1f6b657f14b07fa9b95e50a5a56 Mon Sep 17 00:00:00 2001 From: Ai Hoshino Date: Sun, 9 Jul 2023 22:20:52 +0800 Subject: fix metadata bits of uuid (`randomUUID()`) (#3583) * fix uuid version Close: https://github.com/oven-sh/bun/issues/3575 * add unittest * small fix * avoid unnecessary copying --- test/js/web/web-globals.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test/js/web/web-globals.test.js') diff --git a/test/js/web/web-globals.test.js b/test/js/web/web-globals.test.js index b7a243190..d687a1290 100644 --- a/test/js/web/web-globals.test.js +++ b/test/js/web/web-globals.test.js @@ -138,6 +138,25 @@ it("crypto.randomUUID", () => { }); }); +it("crypto.randomUUID version, issues#3575", () => { + var uuid = crypto.randomUUID(); + + function validate(uuid) { + const regex = + /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i; + return typeof uuid === "string" && regex.test(uuid); + } + function version(uuid) { + if (!validate(uuid)) { + throw TypeError("Invalid UUID"); + } + + return parseInt(uuid.slice(14, 15), 16); + } + + expect(version(uuid)).toBe(4); +}); + it("URL.prototype.origin", () => { const url = new URL("https://html.spec.whatwg.org/"); const { origin, host, hostname } = url; -- cgit v1.2.3 equestBodySize Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
path: root/test/bun.js/process-nexttick.test.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2023-02-13fix(FormData): make String explicit, thanks @dylan-conway (#2065)Gravatar Derrick Farris 1-1/+1
2023-02-13fix(FormData): add string literal operator (#2064)Gravatar Derrick Farris 1-2/+2
2023-02-13Add pretty printer for FormDataGravatar Jarred Sumner 5-1/+101
2023-02-13Add dynamic port assigning to Bun.serve (#2062)Gravatar MichaƂ Warda 3-5/+40
2023-02-13feat(napi): add `napi_get_value_bigint_words` (#2061)Gravatar Derrick Farris 3-0/+44
2023-02-13Fixes https://github.com/oven-sh/bun/issues/1456Gravatar Jarred Sumner 8-1/+148