fix: ensure serverURL has string value for getBaseUploadFields function (#3900)
This commit is contained in:
committed by
GitHub
parent
a4fa0ef393
commit
c564a83ab6
@@ -45,6 +45,10 @@ export const sanitizeConfig = (incomingConfig: Config): SanitizedConfig => {
|
||||
isMergeableObject: isPlainObject,
|
||||
}) as Config
|
||||
|
||||
if (!configWithDefaults.serverURL) {
|
||||
configWithDefaults.serverURL = ''
|
||||
}
|
||||
|
||||
const config: Partial<SanitizedConfig> = sanitizeAdminConfig(configWithDefaults)
|
||||
|
||||
if (config.localization && config.localization.locales?.length > 0) {
|
||||
@@ -92,10 +96,6 @@ export const sanitizeConfig = (incomingConfig: Config): SanitizedConfig => {
|
||||
config.globals = sanitizeGlobals(config as SanitizedConfig)
|
||||
}
|
||||
|
||||
if (typeof config.serverURL === 'undefined') {
|
||||
config.serverURL = ''
|
||||
}
|
||||
|
||||
if (config.serverURL !== '') {
|
||||
config.csrf.push(config.serverURL)
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { audioSlug, enlargeSlug, mediaSlug, reduceSlug, relationSlug } from './s
|
||||
const mockModulePath = path.resolve(__dirname, './mocks/mockFSModule.js')
|
||||
|
||||
export default buildConfigWithDefaults({
|
||||
serverURL: undefined,
|
||||
admin: {
|
||||
webpack: (config) => ({
|
||||
...config,
|
||||
|
||||
@@ -84,6 +84,22 @@ describe('Collections - Uploads', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('should have valid image url', async () => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', fs.createReadStream(path.join(__dirname, './image.png')))
|
||||
|
||||
const { status, doc } = await client.create({
|
||||
file: true,
|
||||
data: formData,
|
||||
})
|
||||
|
||||
expect(status).toBe(201)
|
||||
const expectedPath = path.join(__dirname, './media')
|
||||
expect(await fileExists(path.join(expectedPath, doc.filename))).toBe(true)
|
||||
|
||||
expect(doc.url).not.toContain('undefined')
|
||||
})
|
||||
|
||||
it('creates images that do not require all sizes', async () => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', fs.createReadStream(path.join(__dirname, './small.png')))
|
||||
|
||||
Reference in New Issue
Block a user