svg / svgo

⚙️ Node.js tool for optimizing SVG files
https://svgo.dev/
MIT License
21k stars 1.39k forks source link

Ampersand and equals in href #1638

Open Nineswiss opened 2 years ago

Nineswiss commented 2 years ago

When using this link in a href: https://images.unsplash.com/photo-1627637819794-fba32f82be16?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwyNzk5NDJ8MHwxfHNlYXJjaHw5fHwzZCUyMHJlbmRlcmluZ3xlbnwwfHx8fDE2Mzg0MTc3MDM&ixlib=rb-1.2.1&q=80&w=1080 I get the error 'Invalid character in entity name' at the "=" in "cs=". If I remove the "=" the error is now at the ampersand in "b&f" and so on.

andrewmumblebee commented 2 years ago

I'm also having this issue with image links, also any % symbols get an error, so you can't even url encode the characters

johnkenny54 commented 2 months ago

This seems to work fine in 3.3.2 as long as the href is properly encoded, e.g.

<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
  <image href="https://images.unsplash.com/photo-1627637819794-fba32f82be16?crop=entropy&#38;cs=tinysrgb&#38;fit=max&#38;fm=jpg&#38;ixid=MnwyNzk5NDJ8MHwxfHNlYXJjaHw5fHwzZCUyMHJlbmRlcmluZ3xlbnwwfHx8fDE2Mzg0MTc3MDM&#38;ixlib=rb-1.2.1&#38;q=80&#38;w=1080" height="200" width="200" />
</svg>
GreLI commented 2 months ago

Ampersand is not a valid symbol in XML because of entities. They should be encoded to &amp; entity.