From 17e7a29cb925fe8b54276ac79ee2ea7e8e58effd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C5=ABdolfs=20O=C5=A1i=C5=86=C5=A1?= Date: Wed, 30 Sep 2026 14:46:09 +0200 Subject: [PATCH] Treat RIDs with non-base58 characters as invalid parseRepositoryId threw instead of returning undefined, so the seed form crashed on a typo instead of saying the RID is invalid. --- src/lib/utils.ts | 7 ++++++- tests/unit/utils.test.ts | 17 +++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index f0f37c59c..791e3eff4 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -47,7 +47,12 @@ export function parseRepositoryId( ): { prefix: string; pubkey: string } | undefined { const match = /^(rad:)?(z[a-zA-Z0-9]+)$/.exec(rid); if (match) { - const hex = bs58.decode(match[2].substring(1)); + let hex: Uint8Array; + try { + hex = bs58.decode(match[2].substring(1)); + } catch { + return undefined; + } if (hex.byteLength !== 20) { return undefined; } diff --git a/tests/unit/utils.test.ts b/tests/unit/utils.test.ts index c8996b2dd..b4f52cfea 100644 --- a/tests/unit/utils.test.ts +++ b/tests/unit/utils.test.ts @@ -113,12 +113,17 @@ describe("parseRepositoryId", () => { }); }); - test.each(["", "rad:", "rad:z3fpY7ntt", `${rid} `, "rad:x3fpY7nttPPa6MBn"])( - "rejects %j", - input => { - expect(parseRepositoryId(input)).toBeUndefined(); - }, - ); + test.each([ + "", + "rad:", + "rad:z3fpY7ntt", + `${rid} `, + "rad:x3fpY7nttPPa6MBn", + // Base58 has no 0, O, I or l. + "rad:z0OIl", + ])("rejects %j", input => { + expect(parseRepositoryId(input)).toBeUndefined(); + }); }); describe("formatRepositoryId", () => {