Skip to content
Snippets Groups Projects
Commit 015bc7a0 authored by mathieugrimault's avatar mathieugrimault Committed by Demian Katz
Browse files

Improve tolerance of illegal XML characters (#1290)

parent b55f12d3
No related merge requests found
......@@ -853,11 +853,15 @@ trait MarcAdvancedTrait
{
// Special case for MARC:
if ($format == 'marc21') {
$xml = $this->getMarcRecord()->toXML();
$xml = str_replace(
[chr(27), chr(28), chr(29), chr(30), chr(31), chr(8)], ' ', $xml
$sanitizeXmlRegEx
= '[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+';
$xml = simplexml_load_string(
trim(
preg_replace(
"/$sanitizeXmlRegEx/u", ' ', $this->getMarcRecord()->toXML()
)
)
);
$xml = simplexml_load_string($xml);
if (!$xml || !isset($xml->record)) {
return false;
}
......
......@@ -58,7 +58,10 @@ class Processor
$xsl = new XSLTProcessor();
$xsl->importStyleSheet($style);
$doc = new DOMDocument();
if ($doc->loadXML($xml)) {
$sanitizeXmlRegEx
= '[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+';
$cleanXml = trim(preg_replace("/$sanitizeXmlRegEx/u", ' ', $xml));
if ($doc->loadXML($cleanXml)) {
foreach ($params as $key => $value) {
$xsl->setParameter('', $key, $value);
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment