Skip to content

Commit 927da42

Browse files
authored
fix: limit start, end whitespace in bucket name (#699)
* fix: limit start, end whitespace in bucket name Bucket names shouldn't start or end with spaces to avoid name confusion * fix: move check to createBucket * fix: run with matching prettier version * fix: build failure
1 parent 9d57e50 commit 927da42

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/storage/storage.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ export class Storage {
8686
allowedMimeTypes?: null | string[]
8787
}
8888
) {
89+
// prevent creation with leading or trailing whitespace
90+
if (data.name.trim().length !== data.name.length) {
91+
throw ERRORS.InvalidBucketName(data.name)
92+
}
93+
8994
mustBeValidBucketName(data.name)
9095

9196
const bucketData: Parameters<Database['createBucket']>[0] = data

src/test/bucket.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,23 @@ describe('testing POST bucket', () => {
234234
})
235235
expect(response.statusCode).toBe(400)
236236
})
237+
238+
test('user is not able to create a bucket with the leading and trailing spaces', async () => {
239+
const response = await appInstance.inject({
240+
method: 'POST',
241+
url: `/bucket`,
242+
headers: {
243+
authorization: `Bearer ${process.env.AUTHENTICATED_KEY}`,
244+
},
245+
payload: {
246+
name: ' startsWithSpace',
247+
},
248+
})
249+
expect(response.statusCode).toBe(400)
250+
const { statusCode, error } = await response.json()
251+
expect(statusCode).toBe('400')
252+
expect(error).toBe('Invalid Input')
253+
})
237254
})
238255

239256
/*

0 commit comments

Comments
 (0)