From b8623f11af00c1a9538ebe628b40e4a3add3887d Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Thu, 11 Jan 2024 13:10:30 +0100 Subject: [PATCH] fix: disallow empty key --- src/main.test.ts | 1 + src/store.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/main.test.ts b/src/main.test.ts index 6c71934..140f5d5 100644 --- a/src/main.test.ts +++ b/src/main.test.ts @@ -781,6 +781,7 @@ describe('set', () => { siteID, }) + expect(async () => await blobs.set('', 'value')).rejects.toThrowError('Blob key must not be empty.') expect(async () => await blobs.set('/key', 'value')).rejects.toThrowError( 'Blob key must not start with forward slash (/).', ) diff --git a/src/store.ts b/src/store.ts index 9a085f2..1e0aa23 100644 --- a/src/store.ts +++ b/src/store.ts @@ -307,6 +307,10 @@ export class Store { } private static validateKey(key: string) { + if (key === '') { + throw new Error('Blob key must not be empty.') + } + if (key.startsWith('/') || key.startsWith('%2F')) { throw new Error('Blob key must not start with forward slash (/).') }