From 6ef0c353e239d8a9238e861675b0788db8a64153 Mon Sep 17 00:00:00 2001 From: Philipp Schneider <47689073+philipp-tailor@users.noreply.github.com> Date: Thu, 17 Jul 2025 14:08:53 +0200 Subject: [PATCH] test: add failing test case Seemingly as of 6d1a287dd1e1391425af3fa73842a7bd9ad7ec69, SVG files with the opening `` line are misrecognized as `application/xml`, preventing their upload in collections with `mimeType: 'image/svg+xml'`. This test is added to encourage a fix (e.g. by replacing the dependency), and to prevent future regressions. --- test/uploads/config.ts | 9 +++++++++ test/uploads/int.spec.ts | 16 ++++++++++++++++ test/uploads/shared.ts | 1 + test/uploads/svgWithXml.svg | 9 +++++++++ 4 files changed, 35 insertions(+) create mode 100644 test/uploads/svgWithXml.svg diff --git a/test/uploads/config.ts b/test/uploads/config.ts index 3349d785a9f..dbf3771ca18 100644 --- a/test/uploads/config.ts +++ b/test/uploads/config.ts @@ -40,6 +40,7 @@ import { restrictFileTypesSlug, skipAllowListSafeFetchMediaSlug, skipSafeFetchMediaSlug, + svgOnlySlug, threeDimensionalSlug, unstoredMediaSlug, versionSlug, @@ -910,6 +911,14 @@ export default buildConfigWithDefaults({ BulkUploadsCollection, SimpleRelationshipCollection, FileMimeType, + { + slug: svgOnlySlug, + fields: [], + upload: { + mimeTypes: ['image/svg+xml'], + staticDir: path.resolve(dirname, './svg-only'), + }, + }, ], onInit: async (payload) => { const uploadsDir = path.resolve(dirname, './media') diff --git a/test/uploads/int.spec.ts b/test/uploads/int.spec.ts index ff9ec568115..bb6ceace31e 100644 --- a/test/uploads/int.spec.ts +++ b/test/uploads/int.spec.ts @@ -25,6 +25,7 @@ import { restrictFileTypesSlug, skipAllowListSafeFetchMediaSlug, skipSafeFetchMediaSlug, + svgOnlySlug, unstoredMediaSlug, usersSlug, } from './shared.js' @@ -370,6 +371,21 @@ describe('Collections - Uploads', () => { }) describe('Local API', () => { + describe('create', () => { + it('should create documents when passing filePath', async () => { + const expectedPath = path.join(dirname, './svg-only') + + const svgFilePath = path.resolve(dirname, './svgWithXml.svg') + const doc = await payload.create({ + collection: svgOnlySlug as CollectionSlug, + data: {}, + filePath: svgFilePath, + }) + + expect(await fileExists(path.join(expectedPath, doc.filename))).toBe(true) + }) + }) + describe('update', () => { it('should remove existing media on re-upload - by ID', async () => { // Create temp file diff --git a/test/uploads/shared.ts b/test/uploads/shared.ts index aa0e5a9f2b9..d09ca0a4d19 100644 --- a/test/uploads/shared.ts +++ b/test/uploads/shared.ts @@ -37,3 +37,4 @@ export const constructorOptionsSlug = 'constructor-options' export const bulkUploadsSlug = 'bulk-uploads' export const fileMimeTypeSlug = 'file-mime-type' +export const svgOnlySlug = 'svg-only' diff --git a/test/uploads/svgWithXml.svg b/test/uploads/svgWithXml.svg new file mode 100644 index 00000000000..7b9a928da93 --- /dev/null +++ b/test/uploads/svgWithXml.svg @@ -0,0 +1,9 @@ + + + +