Skip to content

Commit c81fa9a

Browse files
fenosJason
authored andcommitted
Allow special characters as object key
- Modify the method isValidKey to allow special characters - Create a test case verifying that special characters can be used as object key
1 parent 4281329 commit c81fa9a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/storage/limits.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function getFileSizeLimit(
2828
return uploadFileSizeLimit
2929
}
3030

31-
/**
31+
/*true*
3232
* Determines if the image transformation feature is enabled.
3333
* @param tenantId
3434
*/
@@ -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/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)