darylldoyle / svg-sanitizer

A PHP SVG/XML Sanitizer
GNU General Public License v2.0
456 stars 68 forks source link

Allow setting xml options and another bugfix #18

Closed adamroyle closed 5 years ago

adamroyle commented 6 years ago

I noticed that the sanitizer changed this:

<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><title>chevron-double-down</title><path d="M4 11.73l.68-.73L12 17.82 19.32 11l.68.73-7.66 7.13a.5.5 0 0 1-.68 0z"/><path d="M4 5.73L4.68 5 12 11.82 19.32 5l.68.73-7.66 7.13a.5.5 0 0 1-.68 0z"/></svg>

into this:

<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"> <title>chevron-double-down</title> <path d="M4 11.73l.68-.73L12 17.82 19.32 11l.68.73-7.66 7.13a.5.5 0 0 1-.68 0z"></path> <path d="M4 5.73L4.68 5 12 11.82 19.32 5l.68.73-7.66 7.13a.5.5 0 0 1-.68 0z"></path> </svg>

I wanted to remove the extra spaces between elements and allow self-closing tags (ie <path />).

This pull-request fixes both, by adding a setXMLOptions method and by only calling resetInternal before sanitizing. Backwards-compatibility has been maintained.

I've also cleaned up some code formatting to make it a bit easier to read.

darylldoyle commented 5 years ago

Thanks Adam, I’ll go through this tonight and hopefully get it merged :)

darylldoyle commented 5 years ago

Thanks @adamroyle.

That's merged now!