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

SVG data-url built with errors #15257

Closed
7 tasks done
Poyoman39 opened this issue Dec 6, 2023 · 2 comments · Fixed by #15271
Closed
7 tasks done

SVG data-url built with errors #15257

Poyoman39 opened this issue Dec 6, 2023 · 2 comments · Fixed by #15271
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@Poyoman39
Copy link

Describe the bug

  • I'm using vite with react
  • I'm using background-image: url('./someFile.svg'); inside a someFile.module.scss
  • The svg is converted to a data uri at build time
  • The data uri contains error a build time

The bug happens when an svg attribute contains an apostrophe '. in my case i had a <g data-name="some d'ata name"></g>

Reproduction

https://stackblitz.com/edit/vitejs-vite-ifrcfk?file=javascript.svg

Steps to reproduce

You wont see the issue on the reproduction url since it's "dev time" and not after build

  • Build any project with an svg containing data-name="some d'ata name"

  • Then with vite preview for instance, you can see the svg is not rendered and contains an error

  • Built svg has this => data-name='some d'ata name' (apostrophe is not escaped)

System Info

System:
    OS: Linux 6.6 EndeavourOS
    CPU: (16) x64 AMD Ryzen 9 5900HS with Radeon Graphics
    Memory: 18.77 GB / 30.76 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 20.10.0 - /usr/bin/node
    npm: 10.2.4 - /usr/bin/npm
    bun: 1.0.14 - ~/.bun/bin/bun
  Browsers:
    Chromium: 120.0.6099.62
  npmPackages:
    @vitejs/plugin-react-swc: ^3.5.0 => 3.5.0 
    vite: ^5.0.6 => 5.0.6

Used Package Manager

npm

Logs

No response

Validations

Copy link

stackblitz bot commented Dec 6, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@bluwy bluwy added p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Dec 6, 2023
@bluwy
Copy link
Member

bluwy commented Dec 6, 2023

The SVG data uri minifier we have didn't quite anticipated single quotes within attribute values. We currently transform all double quotes as single quotes. Maybe the fix is to detect "...'..." an pre-escape them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants