Skip to content

Commit f616e44

Browse files
author
Jason
committed
Allow special characters as object key
- Modify the method isValidKey to allow special characters - Create a new unit test that verifies special characters are now allowed as object key
1 parent bf91ce2 commit f616e44

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/storage/limits.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export async function isImageTransformationEnabled(tenantId: string) {
4949
export function isValidKey(key: string): boolean {
5050
// only allow s3 safe characters and characters which require special handling for now
5151
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html
52-
return key.length > 0 && /^(\w|\/|!|-|\.|\*|'|\(|\)| |&|\$|@|=|;|:|\+|,|\?)*$/.test(key)
52+
return key.length > 0 && /^[\p{L}\p{N}\p{M}\/!.\-*'()& $@=;:+,?]+\.[\p{L}\p{N}\p{M}]+$/u.test(key)
5353
}
5454

5555
/**

src/test/db/storage/limits.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { isValidKey } from "@storage/limits"
2+
3+
describe("Testing limits", () => {
4+
test("accept special characters as s3 object name", () => {
5+
expect(isValidKey("望舌诊病.pdf")).toBe(true)
6+
expect(isValidKey("ÖÄÜ.jpg")).toBe(true)
7+
expect(isValidKey("åäö.png")).toBe(true)
8+
})
9+
})

0 commit comments

Comments
 (0)