mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-10-18 19:30:27 +08:00
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.
This commit is contained in:
+6
-1
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user