Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trailing slash for default image loader #18298

Merged
merged 2 commits into from Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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