MDL-60943 core_search: Improve exception for preg_replace errors

This commit is contained in:
sam marshall 2017-12-01 15:14:55 +00:00
parent 51e05c09c3
commit 0ce4a24888
2 changed files with 11 additions and 0 deletions

View file

@ -51,6 +51,7 @@ $string['enginenotinstalled'] = 'Engine {$a} is not installed.';
$string['enginenotselected'] = 'You have not selected any search engine.'; $string['enginenotselected'] = 'You have not selected any search engine.';
$string['engineserverstatus'] = 'The search engine is not available. Please contact your administrator.'; $string['engineserverstatus'] = 'The search engine is not available. Please contact your administrator.';
$string['enteryoursearchquery'] = 'Enter your search query'; $string['enteryoursearchquery'] = 'Enter your search query';
$string['error_indexing'] = 'An error occurred while indexing';
$string['errors'] = 'Errors'; $string['errors'] = 'Errors';
$string['errorareanotavailable'] = '{$a} search area is not available.'; $string['errorareanotavailable'] = '{$a} search area is not available.';
$string['filesinindexdirectory'] = 'Files in index directory'; $string['filesinindexdirectory'] = 'Files in index directory';

View file

@ -280,6 +280,16 @@ class document implements \renderable, \templatable {
} else { } else {
// Replace all groups of line breaks and spaces by single spaces. // Replace all groups of line breaks and spaces by single spaces.
$this->data[$fieldname] = preg_replace("/\s+/u", " ", $value); $this->data[$fieldname] = preg_replace("/\s+/u", " ", $value);
if ($this->data[$fieldname] === null) {
if (isset($this->data['id'])) {
$docid = $this->data['id'];
} else {
$docid = '(unknown)';
}
throw new \moodle_exception('error_indexing', 'search', '', null, '"' . $fieldname .
'" value causes preg_replace error (may be caused by unusual characters) ' .
'in document with id "' . $docid . '"');
}
} }
return $this->data[$fieldname]; return $this->data[$fieldname];