diff --git a/includes/coins.inc b/includes/coins.inc index 7b3308f8..87423d17 100644 --- a/includes/coins.inc +++ b/includes/coins.inc @@ -51,7 +51,16 @@ class Coins { drupal_set_message(t('No MODS datastream found!'), 'warning'); return " "; } - $xml = new SimpleXMLElement($xmlstr); + try { + $xml = new SimpleXMLElement(islandora_sanitize_input_for_valid_xml($xmlstr)); + } + catch (Exception $e) { + watchdog('islandora_scholar', 'The "@dsid" of "@pid" could not be parsed as XML.', array( + '@dsid' => 'MODS', + '@pid' => $object->id, + ), WATCHDOG_WARNING, l(t("manage object"), "islandora/object/{$object->id}/manage/datastreams")); + return " "; + } $xml->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3'); $this->mods = $xml; diff --git a/includes/upload.tab.inc b/includes/upload.tab.inc index 681b5f2a..8fb6bbf2 100644 --- a/includes/upload.tab.inc +++ b/includes/upload.tab.inc @@ -43,7 +43,16 @@ function islandora_scholar_modify_form(array $form, array &$form_state, Abstract $mods_doc = new DOMDocument(); $mods_doc->loadXML($mods_str); - $mods_xpath = new DOMXPath($mods_doc); + try { + $mods_xpath = new DOMXPath(islandora_sanitize_input_for_valid_xml($mods_doc)); + } + catch (Exception $e) { + watchdog('islandora_scholar', 'The upload of "@dsid" of "@pid" could not be parsed as XML.', array( + '@dsid' => 'MODS', + '@pid' => $object->id, + ), WATCHDOG_WARNING, l(t("manage object"), "islandora/object/{$object->id}/manage/datastreams")); + return " "; + } $mods_xpath->registerNamespace('m', 'http://www.loc.gov/mods/v3'); $usage = t('No usage statement'); $mods_usages = $mods_xpath->query('//m:mods/m:accessCondition[@type="use and reproduction"]'); diff --git a/modules/citeproc/includes/converter.inc b/modules/citeproc/includes/converter.inc index 143e9461..0c33e420 100644 --- a/modules/citeproc/includes/converter.inc +++ b/modules/citeproc/includes/converter.inc @@ -106,7 +106,7 @@ function convert_mods_to_citeproc_jsons($mods_in) { } else { try { - $mods = simplexml_load_string($mods_in); + $mods = simplexml_load_string(islandora_sanitize_input_for_valid_xml($mods_in)); } catch (Exception $e) { watchdog('citeproc', 'Got exception while parsing. Message: !msg Errors: !error', array( diff --git a/modules/islandora_google_scholar/islandora_google_scholar.module b/modules/islandora_google_scholar/islandora_google_scholar.module index 490c84b9..9a436e80 100644 --- a/modules/islandora_google_scholar/islandora_google_scholar.module +++ b/modules/islandora_google_scholar/islandora_google_scholar.module @@ -24,10 +24,17 @@ function islandora_google_scholar_create_meta_tags($object) { else { $tags = array(); $tags['citation_author'] = array(); - // remove breaking control characters. - $object['MODS']->content = preg_replace('/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F]/', '', $object['MODS']->content); $mods = $object['MODS']->content; - $mods_xml = new SimpleXMLElement($mods); + try { + $mods_xml = new SimpleXMLElement(islandora_sanitize_input_for_valid_xml($mods)); + } + catch (Exception $e) { + watchdog('islandora_google_scholar', 'The "@dsid" of "@pid" could not be parsed as XML.', array( + '@dsid' => 'MODS', + '@pid' => $object->id, + ), WATCHDOG_WARNING, l(t("manage object"), "islandora/object/{$object->id}/manage/datastreams")); + return FALSE; + } $mods_xml->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3'); $title_results = $mods_xml->xpath(variable_get('islandora_scholar_xpaths_title', '//mods:mods[1]/mods:titleInfo/mods:title'));