Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
Check SVG with JS dompurify

I'm using DomPurify to sanitize SVG code.

It works fine however I would like to show a message if SVG code entered in a textarea is not valid.

I'm trying to compare the SVG code added with the SVG code sanitized. If they are different I will show a message.

function validate() {
  if( svgCode.trim() === DOMPurify.sanitize(svgCode).trim() ) {
    console.log('All right!');
  } else {
    console.log('Uuuh-oooh! The SVG code is not valid!');
  }
}

validate();

The issue: I keep getting Uuuh-oooh! The SVG code is not valid! because dompurify turns closing paths like /> into full paths '`.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use removed property to check if any sanitization happened or not.

e.g.

  DOMPurify.sanitize('<svg onload=alert(1) />');
  console.log(DOMPurify.removed.length); // 1
  DOMPurify.sanitize('<svg />');
  console.log(DOMPurify.removed.length); // 0

https://github.com/is2ei/DOMPurify#okay-makes-sense-lets-move-on

After sanitizing your markup, you can also have a look at the property DOMPurify.removed and find out, what elements and attributes were thrown out. Please do not use this property for making any security critical decisions. This is just a little helper for curious minds.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda