未验证 提交 f7ba546e 编写于 作者: S Steven 提交者: GitHub

Fix trailing slash for default image loader (#18298)

Co-authored-by: Nkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
上级 ab0b0a8a
......@@ -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(
......@@ -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) {
......
......@@ -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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册