Giter Club home page Giter Club logo

Comments (3)

eluisfonseca avatar eluisfonseca commented on June 1, 2024

The svg is valid, according to W3C standards. The issue has to do with the regex being used:

/^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*\s*(?:\[?(?:\s*<![^>]*>\s*)*\]?)*[^>]*>\s*)?(?:<svg[^>]*>[^]*<\/svg>|<svg[^/>]*\/\s*>)\s*$/i

As it is, due to this part of the expression: \[?(?:\s*<![^>]*>\s*)*\] it does not allow for markup to be included in an Entity's internal subset. If you remove them, isSvg() returns true.

To fix this we could simply remove > has a forbidden character to occur inside the square brackets of the doctype tag (with the end expression being: /^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*\s*(?:\[?(?:\s*<![^]*>\s*)*\]?)*[^>]*>\s*)?(?:<svg[^>]*>[^]*<\/svg>|<svg[^/>]*\/\s*>)\s*$/i

Or update the regex to allow for markup. I tried to come up with something. but allowing for markup would mean we would need to allow for pretty much anything. So I went with allowing any content to be added when inside double quotes. Like so:
/^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*\s*(?:\[?(?:\s*<!\s*[^]*(?:\"[^]*\")*\s*>\s*)*\]?)*[^>]*>\s*)?(?:<svg[^>]*>[^]*<\/svg>|<svg[^/>]*\/\s*>)\s*$/i

But this would make the function even dirtier as it would allow for any type of scrap to happen inside the doctype tag. Are any of these solutions viable? Any ideas? I can open a PR and address this.

from is-svg.

sindresorhus avatar sindresorhus commented on June 1, 2024

@eluisfonseca How about a regex that strips out markup (or just everything) from inside the entity before running the detection?

from is-svg.

eluisfonseca avatar eluisfonseca commented on June 1, 2024

Good idea. So we'll do no check of the entity's content and just remove it and then just validate the what is left. I'll look into it.

from is-svg.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.