From f616e444272966d137981219ed6fdac9d90c59ff Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 24 Sep 2024 22:59:25 +0700 Subject: [PATCH] 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 --- src/storage/limits.ts | 2 +- src/test/db/storage/limits.test.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/test/db/storage/limits.test.ts diff --git a/src/storage/limits.ts b/src/storage/limits.ts index cff8627d..7396332f 100644 --- a/src/storage/limits.ts +++ b/src/storage/limits.ts @@ -49,7 +49,7 @@ export async function isImageTransformationEnabled(tenantId: string) { export function isValidKey(key: string): boolean { // only allow s3 safe characters and characters which require special handling for now // https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html - return key.length > 0 && /^(\w|\/|!|-|\.|\*|'|\(|\)| |&|\$|@|=|;|:|\+|,|\?)*$/.test(key) + return key.length > 0 && /^[\p{L}\p{N}\p{M}\/!.\-*'()& $@=;:+,?]+\.[\p{L}\p{N}\p{M}]+$/u.test(key) } /** diff --git a/src/test/db/storage/limits.test.ts b/src/test/db/storage/limits.test.ts new file mode 100644 index 00000000..9188d9da --- /dev/null +++ b/src/test/db/storage/limits.test.ts @@ -0,0 +1,9 @@ +import { isValidKey } from "@storage/limits" + +describe("Testing limits", () => { + test("accept special characters as s3 object name", () => { + expect(isValidKey("望舌诊病.pdf")).toBe(true) + expect(isValidKey("ÖÄÜ.jpg")).toBe(true) + expect(isValidKey("åäö.png")).toBe(true) + }) +})