Unverified Commit f7ba546e authored by Steven's avatar Steven Committed by GitHub

Fix trailing slash for default image loader (#18298)

Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent ab0b0a8a
...@@ -218,18 +218,12 @@ function assignDefaults(userConfig: { [key: string]: any }) { ...@@ -218,18 +218,12 @@ function assignDefaults(userConfig: { [key: string]: any }) {
if (result?.images) { if (result?.images) {
const { images } = result const { images } = result
// Normalize defined image host to end in slash
if (images?.path) {
if (images.path[images.path.length - 1] !== '/') {
images.path += '/'
}
}
if (typeof images !== 'object') { if (typeof images !== 'object') {
throw new Error( throw new Error(
`Specified images should be an object received ${typeof images}` `Specified images should be an object received ${typeof images}`
) )
} }
if (images.domains) { if (images.domains) {
if (!Array.isArray(images.domains)) { if (!Array.isArray(images.domains)) {
throw new Error( throw new Error(
...@@ -306,6 +300,14 @@ function assignDefaults(userConfig: { [key: string]: any }) { ...@@ -306,6 +300,14 @@ function assignDefaults(userConfig: { [key: string]: any }) {
) )
} }
} }
// Append trailing slash for non-default loaders
if (images.path) {
const isDefaultLoader = !images.loader || images.loader === 'default'
if (!isDefaultLoader && images.path[images.path.length - 1] !== '/') {
images.path += '/'
}
}
} }
if (result.experimental?.i18n) { if (result.experimental?.i18n) {
......
...@@ -71,10 +71,7 @@ function runTests(mode) { ...@@ -71,10 +71,7 @@ function runTests(mode) {
expect( expect(
await hasImageMatchingUrl( await hasImageMatchingUrl(
browser, browser,
mode === 'serverless' `http://localhost:${appPort}/_next/image?url=%2Ftest.jpg&w=420&q=75`
? // FIXME: this is a bug
`http://localhost:${appPort}/_next/image/?url=%2Ftest.jpg&w=420&q=75`
: `http://localhost:${appPort}/_next/image?url=%2Ftest.jpg&w=420&q=75`
) )
).toBe(true) ).toBe(true)
} finally { } finally {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment