Skip to content

Commit

Permalink
Wrap in a Try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
DonRichards committed Apr 15, 2019
1 parent efd3185 commit c979e03
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
11 changes: 10 additions & 1 deletion includes/coins.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion includes/upload.tab.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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"]');
Expand Down
2 changes: 1 addition & 1 deletion modules/citeproc/includes/converter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 10 additions & 3 deletions modules/islandora_google_scholar/islandora_google_scholar.module
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit c979e03

Please sign in to comment.