Skip to content

Commit

Permalink
MDL-60943 core_search: Improve exception for preg_replace errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed Jan 4, 2018
1 parent 013f0b2 commit d20ec36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lang/en/search.php
Expand Up @@ -52,6 +52,7 @@
$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';
Expand Down
10 changes: 10 additions & 0 deletions search/classes/document.php
Expand Up @@ -280,6 +280,16 @@ public function set($fieldname, $value) {
} 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];
Expand Down

0 comments on commit d20ec36

Please sign in to comment.