Skip to content

Commit

Permalink
Fallback to regular search if searching with `ignore_accented_charact…
Browse files Browse the repository at this point in the history
…ers` on an unsupported charset raises an exception [#107]
  • Loading branch information
flaviocopes committed Apr 11, 2017
1 parent 42ae10d commit a5b5786
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

1. [](#bugfix)
* Default `ignore_accented_characters` to false
* Fallback to regular search if searching with `ignore_accented_characters` on an unsupported charset raises an exception [#107](https://github.com/getgrav/grav-plugin-simplesearch/issues/107)

# v1.10.0
## 01/23/2017
Expand Down
6 changes: 5 additions & 1 deletion simplesearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,11 @@ public function onTwigSiteVariables()
private function matchText($haystack, $needle) {
if ($this->config->get('plugins.simplesearch.ignore_accented_characters')) {
setlocale(LC_ALL, 'en_US');
$result = mb_stripos(iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $haystack), iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $needle));
try {
$result = mb_stripos(iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $haystack), iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $needle));
} catch (\Exception $e) {
$result = mb_stripos($haystack, $needle);
}
setlocale(LC_ALL, '');
return $result;
} else {
Expand Down

0 comments on commit a5b5786

Please sign in to comment.