Commit 20c08701 authored by js's avatar js Committed by Robert Lyon
Browse files

Bug 1676596: Leap2A failing to import content with  



Patch does:
- Convert   to a space
- Give better xml fail message when failing on bad characters

behatnotneeded

Change-Id: I3df9221010080a7dde7c4f13531193a2bd6a12f3
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 7ecbb373
......@@ -124,15 +124,31 @@ class PluginImportLeap extends PluginImport {
;
libxml_before(false);
require_once('file.php');
if (!$this->xml = simplexml_load_string(
preg_replace(xml_filter_regex(), '', file_get_contents($this->filename)),
'SimpleXMLElement',
$options
)) {
// TODO: bail out in a much nicer way...
libxml_use_internal_errors(true);
$raw_contents = file_get_contents($this->filename);
// failing on &nbsp; so let's replace them!
$cooked_contents = preg_replace('/&nbsp;/', ' ', $raw_contents);
$sxe = simplexml_load_string(
preg_replace(xml_filter_regex(), '', $cooked_contents),
'SimpleXMLElement',
$options
);
if ($sxe === false) {
$msg = [];
$msg[] = 'FATAL: XML not well formed';
foreach (libxml_get_errors() as $error) {
$msg[] = $error->message;
}
// uncomment for even more data
// $msg[] = 'INPUT';
// $msg[] = $cooked_contents;
libxml_after();
throw new ImportException($this, "FATAL: XML file is not well formed! Please consult Mahara's error log for more information");
$msgString = implode("\n", $msg);
throw new ImportException($this, $msgString);
}
$this->xml = $sxe;
libxml_after();
$this->namespaces = array_flip($this->xml->getDocNamespaces());
......
Markdown is supported
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