Skip to content

Commit

Permalink
fix: disallow empty key (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skn0tt authored Jan 11, 2024
1 parent b666247 commit a8b4a23
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (/).',
)
Expand Down
4 changes: 4 additions & 0 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (/).')
}
Expand Down

0 comments on commit a8b4a23

Please sign in to comment.