Skip to content

Commit

Permalink
Fix trailing slash for default image loader (#18298)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
styfle and kodiakhq[bot] committed Oct 27, 2020
1 parent ab0b0a8 commit f7ba546
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
16 changes: 9 additions & 7 deletions packages/next/next-server/server/config.ts
Expand Up @@ -218,18 +218,12 @@ function assignDefaults(userConfig: { [key: string]: any }) {
if (result?.images) {
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') {
throw new Error(
`Specified images should be an object received ${typeof images}`
)
}

if (images.domains) {
if (!Array.isArray(images.domains)) {
throw new Error(
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions test/integration/image-component/default/test/index.test.js
Expand Up @@ -71,10 +71,7 @@ function runTests(mode) {
expect(
await hasImageMatchingUrl(
browser,
mode === 'serverless'
? // 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`
`http://localhost:${appPort}/_next/image?url=%2Ftest.jpg&w=420&q=75`
)
).toBe(true)
} finally {
Expand Down

0 comments on commit f7ba546

Please sign in to comment.