Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Add test

istarkov732a39e5671c
diff --git a/packages/asset-uploader/src/utils/sanitize-s3-key.test.ts b/packages/asset-uploader/src/utils/sanitize-s3-key.test.ts
new file mode 100644
index 0000000000..50578290c5
--- /dev/null
+++ b/packages/asset-uploader/src/utils/sanitize-s3-key.test.ts
@@ -0,0 +1,46 @@
+import { sanitizeS3Key } from "./sanitize-s3-key";
+
+describe("sanitizeS3Key", () => {
+ test("Should replace ASCII character ranges 00–1F hex (0–31 decimal) and 7F (127 decimal)", () => {
+ let path = "";
+ for (let i = 0; i < 32; ++i) {
+ path += String.fromCharCode(i) + "abc";
+ }
+ path += String.fromCharCode(127);
+
+ expect(sanitizeS3Key(path)).toMatchInlineSnapshot(
+ `"_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_abc_"`
+ );
+ });
+
+ test(`Should replace "&" "$" "@" "=" ";" "/" ":" "+" "," "?"`, () => {
+ const path = `test&test$test@test=test;test/test:test+test,test?test`;
+ expect(sanitizeS3Key(path)).toMatchInlineSnapshot(
+ `"test_test_test_test_test_test_test_test_test_test_test"`
+ );
+ });
+
+ test("Non-printable ASCII characters (128–255 decimal characters)", () => {
+ let path = "";
+ for (let i = 128; i < 256; ++i) {
+ path += String.fromCharCode(i) + "a";
+ }
+ path += String.fromCharCode(127);
+
+ expect(sanitizeS3Key(path)).toMatchInlineSnapshot(
+ `"_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_"`
+ );
+ });
+
+ test(`Should replace "\\" "{" "^" "}" "%" "\`" "]" "'" """ "“" "”" ">" "[" "~" "<" "#" "|"`, () => {
+ const path = `x\\x{x^x}x%x\`x]x'x"x“x”x>x[x~x<x#x|`;
+ expect(sanitizeS3Key(path)).toMatchInlineSnapshot(
+ `"x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_x_"`
+ );
+ });
+
+ test(`Should do nothing with ordinary utf caracters`, () => {
+ const path = `hello-world-привет-мир-😀-😂ĊĴĈ`;
+ expect(sanitizeS3Key(path)).toMatch(path);
+ });
+});