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 013f0b2266
commit d20ec3606b
2 changed files with 11 additions and 0 deletions

View File

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

View File

@ -280,6 +280,16 @@ class document implements \renderable, \templatable {
} else {
// Replace all groups of line breaks and spaces by single spaces.
$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];