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

next/image produces invalid HTML according to W3C (again) #33809

Closed
theoludwig opened this issue Jan 30, 2022 · 5 comments · Fixed by #33825
Closed

next/image produces invalid HTML according to W3C (again) #33809

theoludwig opened this issue Jan 30, 2022 · 5 comments · Fixed by #33825
Assignees
Labels
Image (next/image) Related to Next.js Image Optimization.

Comments

@theoludwig
Copy link
Contributor

Run next info (available from version 12.0.8 and up)

Operating System:
  Platform: linux
  Arch: x64
  Version: #29-Ubuntu SMP Wed Jan 12 17:36:47 UTC 2022
Binaries:
  Node: 16.13.2
  npm: 8.3.2
  Yarn: 1.22.15
  pnpm: 6.11.0
Relevant packages:
  next: 12.0.9
  react: 17.0.2
  react-dom: 17.0.2

What version of Next.js are you using?

12.0.9

What version of Node.js are you using?

16.13.2

What browser are you using?

N/A

What operating system are you using?

N/A

How are you deploying your application?

N/A

Describe the Bug

Using next@12.0.7 yields no invalid HTML errors on the W3C Markup Validation Service about next/image.

After upgrading to next@12.0.9, there is now this kind of error:

Error: Bad value data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 version=%271.1%27 width=%271000%27 height=%271000%27/%3e 
for attribute src on element img: Illegal character in scheme data: space is not allowed.

image

There was already an error similar to this one before but that has been fixed: #18850
We might add a new e2e test or CI job to ensure that next produces valid HTML according to W3C, so it's not happening again as it is the case now...

Expected Behavior

No errors. Valid HTML according to W3C.

To Reproduce

  1. npx create-next-app --example image-component image-app
  2. cd image-app
  3. npm run build
  4. npm run start
  5. Go to localhost:3000 and copy/paste the HTML in The W3C Markup Validation Service or use the
    html-w3c-validator CLI
    .
@theoludwig theoludwig added the bug Issue was opened via the bug report template. label Jan 30, 2022
@theoludwig
Copy link
Contributor Author

It might be because of this PR: #33218.
We should probably revert this PR or find a solution.

@sokra
Copy link
Member

sokra commented Jan 31, 2022

We should be able to encode space with +. Do you want to send a PR for that?

@theoludwig
Copy link
Contributor Author

Sure, I can open a PR (by first working to have a failing test)! 👍
@sokra As far as I understood, the problematic line is this one:

sizerSvgUrl = `data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 version=%271.1%27 width=%27${widthInt}%27 height=%27${heightInt}%27/%3e`

Is adding + instead of space would resolve the issue?
So something like that:

sizerSvgUrl = `data:image/svg+xml,%3csvg+xmlns=%27http://www.w3.org/2000/svg%27+version=%271.1%27+width=%27${widthInt}%27+height=%27${heightInt}%27/%3e`

If it is what is wanted, yes I will open a PR. 😄

@balazsorban44 balazsorban44 added Image (next/image) Related to Next.js Image Optimization. kind: bug and removed bug Issue was opened via the bug report template. labels Jan 31, 2022
@theoludwig
Copy link
Contributor Author

theoludwig commented Jan 31, 2022

PR is up: #33825

Thanks for your help to resolve this issue, could you review the PR, please ? 😄 @sokra

@styfle styfle self-assigned this Jan 31, 2022
styfle pushed a commit that referenced this issue Feb 1, 2022
## Bug

- [x] Fixes #33809
- [x] Related to #33218
- [x] Integration tests added: Usage of [html-validator](https://www.npmjs.com/package/html-validator) to validate the HTML.
- [x] Errors have helpful link attached, see `contributing.md` (N/A)
natew pushed a commit to natew/next.js that referenced this issue Feb 16, 2022
## Bug

- [x] Fixes vercel#33809
- [x] Related to vercel#33218
- [x] Integration tests added: Usage of [html-validator](https://www.npmjs.com/package/html-validator) to validate the HTML.
- [x] Errors have helpful link attached, see `contributing.md` (N/A)
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Image (next/image) Related to Next.js Image Optimization.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants