aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-07-09 22:20:52 +0800
committerGravatar GitHub <noreply@github.com> 2023-07-09 07:20:52 -0700
commit565d1689e9f2c1f6b657f14b07fa9b95e50a5a56 (patch)
tree8534cb81892929de7846b9cdc2056ce68d02e5a9 /test
parent59570fe237f91dd04ce8f37779902cffa4352010 (diff)
downloadbun-565d1689e9f2c1f6b657f14b07fa9b95e50a5a56.tar.gz
bun-565d1689e9f2c1f6b657f14b07fa9b95e50a5a56.tar.zst
bun-565d1689e9f2c1f6b657f14b07fa9b95e50a5a56.zip
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
Diffstat (limited to 'test')
-rw-r--r--test/js/web/web-globals.test.js19
1 files changed, 19 insertions, 0 deletions
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;