From b829adeee3d97e19ce082416232e4b8855e85818 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 27 Oct 2020 09:55:21 -0400 Subject: [PATCH] Fix trailing slash for default image loader --- packages/next/next-server/server/config.ts | 16 +++++++++------- .../image-component/default/test/index.test.js | 5 +---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/next/next-server/server/config.ts b/packages/next/next-server/server/config.ts index dafb6332c433fec..55d384b46019129 100644 --- a/packages/next/next-server/server/config.ts +++ b/packages/next/next-server/server/config.ts @@ -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) { diff --git a/test/integration/image-component/default/test/index.test.js b/test/integration/image-component/default/test/index.test.js index c2c6eda216076c6..aec76d72a37a654 100644 --- a/test/integration/image-component/default/test/index.test.js +++ b/test/integration/image-component/default/test/index.test.js @@ -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 {