Skip to content
Permalink
Browse files Browse the repository at this point in the history
Always use delimiter not present in search expression
This avoids need to figure out correct escaping in case delimiter is
present in the expression.

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jun 20, 2016
1 parent 2f49508 commit 4bcc606
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion libraries/controllers/table/TableSearchController.php
Expand Up @@ -726,9 +726,22 @@ private function _getRegexReplaceRows(
$result = $this->dbi->fetchResult($sql_query, 0);

if (is_array($result)) {
/* Iterate over possible delimiters to get one */
$delimiters = array('/', '@', '#', '~', '!', '$', '%', '^', '&', '_');
$found = false;
for ($i = 0; $i < count($delimiters); $i++) {
if (strpos($find, $delimiters[$i]) === false) {
$found = true;
break;
}
}
if (! $found) {
return false;
}
$find = $delimiters[$i] . $find . $delimiters[$i];
foreach ($result as $index=>$row) {
$result[$index][1] = preg_replace(
"/" . $find . "/",
$find,
$replaceWith,
$row[0]
);
Expand Down

0 comments on commit 4bcc606

Please sign in to comment.