Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/next/server/image-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,22 @@ export async function imageOptimizer(
}

const { headers } = req
const { url, w, q } = parsedUrl.query
const { url: decodedUrl, w, q } = parsedUrl.query
const mimeType = getSupportedMimeType(MODERN_TYPES, headers.accept)
let href: string

if (!url) {
if (!decodedUrl) {
res.statusCode = 400
res.end('"url" parameter is required')
return { finished: true }
} else if (Array.isArray(url)) {
} else if (Array.isArray(decodedUrl)) {
res.statusCode = 400
res.end('"url" parameter cannot be an array')
return { finished: true }
}

const url = encodeURI(decodedUrl)

let isAbsolute: boolean

if (url.startsWith('/')) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions test/integration/image-optimizer/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ function runTests({ w, isDev, domains = [], ttl, isSharp }) {
expect(await res.text()).toMatch(/Image Optimizer Home/m)
})

it('should handle non-ascii characters in image url', async () => {
const query = { w, q: 90, url: '/äöü.png' }
const res = await fetchViaHTTP(appPort, '/_next/image', query, {})
expect(res.status).toBe(200)
})

it('should maintain animated gif', async () => {
const query = { w, q: 90, url: '/animated.gif' }
const res = await fetchViaHTTP(appPort, '/_next/image', query, {})
Expand Down