Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
Compruebe SVG con JS dompurify

Estoy usando DomPurify para desinfectar el código SVG.

Funciona bien, sin embargo, me gustaría mostrar un mensaje si el código SVG ingresado en un área de texto no es válido.

Estoy tratando de comparar el código SVG agregado con el código SVG desinfectado. Si son diferentes mostraré un mensaje.

 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();

El problema: ¡Sigo recibiendo Uuuh-oooh! The SVG code is not valid! porque dompurify convierte las rutas de cierre como /> en rutas completas ''.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar la propiedad removed para verificar si se realizó o no alguna desinfección.

p.ej

 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-let-move-on

Después de desinfectar su marcado, también puede echar un vistazo a la propiedad DOMPurify.removed y averiguar qué elementos y atributos se eliminaron. No utilice esta propiedad para tomar decisiones críticas de seguridad. Esto es solo un pequeño ayudante para mentes curiosas.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!