XML header lines removed
angrybrad opened this issue · comments
If you have an SVG files that begins with <?xml version="1.0" encoding="utf-8"?>
, then Sanitizer will remove that when saving the clean XML elements back out to the XML file.
It happens in this line:
$clean = $this->xmlDocument->saveXML($this->xmlDocument->documentElement, LIBXML_NOEMPTYTAG);
The reason is that all of the XML header info (verison, encoding, etc.) is saved on $this->xmlDocument
. Changing that line to:
$clean = $this->xmlDocument->saveXML($this->xmlDocument, LIBXML_NOEMPTYTAG);
Makes it behave as you'd expect. Just making sure that wasn't a conscious design decision before I submit a pull request.
Hey @takobell,
Unless I'm overlooking something silly because it's late then I see no reason we can't enable the XML declaration to be returned.
I think originally because I was basing the library on DOMPurify I copied the way their library works. As theirs is all inline SVG, the XML declaration isn't required and is therefore stripped but I see how it could be useful in this lib.
Test data will need updating to take this change into account, are you happy to do that? If not then feel free to make a PR for the change and I'll update the tests :)
PR: #12
Tried to get phpunit up and running to update the tests, but was getting tons of random errors.
Thanks @takobell, tests passed fine once updated and it's now been merged into 0.6.0
:)
Thanks, @darylldoyle!