next.js: image optimizer returns 400 when path contains unicode characters

What version of Next.js are you using?

11.0.1

What version of Node.js are you using?

14.17.2

What browser are you using?

firefox

What operating system are you using?

ubuntu

How are you deploying your application?

vercel

Describe the Bug

in a production build, the image optimizer returns with status code 400, and error message “The requested resource isn’t a valid image” when the image src contains non-ascii unicode characters.

Expected Behavior

image optimizer should handle paths with all allowed unicode characters

To Reproduce

  1. clone https://github.com/stefanprobst/issue-next-image-optimizer and yarn install
  2. run yarn build && yarn start
  3. there should be an image visible at http://localhost:3000, but there isn’t. the network panel reports status code 400, error message “The requested resource isn’t a valid image.” which comes from here
  4. note that when running yarn dev the image is visible

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (20 by maintainers)

Commits related to this issue

Most upvoted comments

The fix is available in v11.0.2-canary.25

You can try it out with yarn add next@canary, thanks!

sure, done in #27671

ok, so what appears to be happening is that the “public folder catchall” route does not correctly match here: https://github.com/vercel/next.js/blob/34d418c12d593c4180f805fc51229259caa5e28a/packages/next/server/next-server.ts#L1142

this is what i get here: next-server-L1137

you can see that the publicFiles Set is URI-encoded, but the /leärn.png path is not (probably because it is taken from a query param?).

Perhaps it has something to do with the language/locale of your browser?

i have de, and my system locale is de_AT. however, checking with firefox nightly (without any languages installed), started with LANG=C firefox-trunk gives the same error:

Screenshot_20210730_080808

i have now tried in a Windows 10 VM, and can reproduce the same error there as well, so it’s not a linux-specific thing.