Regexes with super-linear backtracking (S8786 x16) are rewritten to stay linear on long runs; each new pattern gives the same results as the old one on 150k-450k fuzzed inputs (except where noted) and finishes adversarial 50k-character inputs in under 3 ms: - tag-generator QUALIFIER_SUFFIX_RE starts just before a `:`/space run (`(^|[^:\s])…` + "$1"), never inside one - timeline-parser matches `line.trimEnd()` with a greedy label, and renders with trimEnd(); cleanCpuName collapses whitespace before the patterns - editor-store endings, Google Play urlPattern (lookahead for `id=`), channel-phrase punctuation, SPDX OR/AND split, legal-docs slug and link stripping (link text/URL may not contain `[`), base64url padding, and a loop for trailing slashes in the worker router Others: - S2871: sorts take the shared code-unit comparator (same order as before; THIRD_PARTY_NOTICES is unchanged) - S4822: ErrorBoundary catches the logger import with .catch(), which a try/catch never could - S3516: migrateProfilesState returns a new object - S7773: Number.parseInt (x10) - S9379: Modal takes an initialFocusRef (Radix onOpenAutoFocus), so the shortcut search box gets focus without an autoFocus attribute - S2245: generateId drops the Math.random fallback; getRandomValues exists everywhere the app runs, and a non-random ID is worse than an error - S4036: NOSONAR on the dev script's `git` call (PATH lookup by design) - S6505/S8543: every workflow installs with `npm ci --ignore-scripts`, and CI runs `npm run cf:check` instead of `npx wrangler …` - S6358: Android sets allowBackup="false" — app data is no longer copied to Google Drive backups; Backup & Restore moves it to a new phone Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.4 KiB
TypeScript
38 lines
1.4 KiB
TypeScript
import { describe, it, expect, afterEach, vi } from "vitest";
|
|
import { generateId } from "@utils/uuid";
|
|
|
|
// RFC 4122 v4: 8-4-4-4-12 hex, version nibble "4", variant nibble 8/9/a/b.
|
|
const V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
|
|
describe("generateId", () => {
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
});
|
|
|
|
it("returns a valid v4 UUID via the native crypto.randomUUID path", () => {
|
|
expect(generateId()).toMatch(V4);
|
|
});
|
|
|
|
it("falls back to a valid v4 UUID when crypto.randomUUID is missing", () => {
|
|
// Insecure contexts (and Chromium < 92) have getRandomValues but not
|
|
// randomUUID — the gap that once black-screened the app at boot.
|
|
const real = globalThis.crypto;
|
|
vi.stubGlobal("crypto", {
|
|
getRandomValues: (a: Uint8Array<ArrayBuffer>) => real.getRandomValues(a),
|
|
});
|
|
expect(generateId()).toMatch(V4);
|
|
});
|
|
|
|
it("refuses to make up an ID when there is no crypto at all", () => {
|
|
// No Math.random fallback: an ID that is not random is worse than an
|
|
// error. Every engine the app supports has crypto.getRandomValues.
|
|
vi.stubGlobal("crypto", undefined);
|
|
expect(() => generateId()).toThrow(TypeError);
|
|
});
|
|
|
|
it("produces unique values across many calls", () => {
|
|
const ids = new Set(Array.from({ length: 1000 }, () => generateId()));
|
|
expect(ids.size).toBe(1000);
|
|
});
|
|
});
|