Skip to content

Commit 3fca7d3

Browse files
committed
Search now uses regex (insensitive mode)
1 parent 8e39b9e commit 3fca7d3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Commands/SearchLog.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ public function handle() {
2323
}
2424

2525
protected function addHighlightingToRecord(LogRecord $record): LogRecord {
26-
$message = str_replace($this->filter['search'], '<bg=yellow>'.$this->filter['search'].'</>', $record['message']);
26+
$message = preg_replace(
27+
[
28+
'/('.$this->filter['search'].')/i',
29+
'/\\\\<bg=yellow>('.$this->filter['search'].')<\/>/i', // the sequence \<bg=yellow> causes errors, even when everything is escaped like \\<...> (maybe a Symfony bug?)
30+
],
31+
[
32+
'<bg=yellow>$1</>',
33+
'<bg=yellow>\\\\$1</>', // solution to the issue above: include the backslash in the highlighting
34+
],
35+
$record['message']);
2736
$driver = $record->getDriver();
2837
$record = new LogRecord(
2938
$record['datetime'],

src/Models/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getFilteredRecords(array $filter): array {
5151
$records = array_filter($records, fn($record) => strtolower($record['level']) == $level);
5252
}
5353
if(isset($filter['search'])) {
54-
$records = array_filter($records, fn($record) => (strpos($record['message'], $filter['search']) !== false));
54+
$records = array_filter($records, fn($record) => (preg_match('/'.$filter['search'].'/i', $record['message']) === 1));
5555
}
5656
if(isset($filter['count']) && count($records) > $filter['count']) {
5757
// only return the last $count

0 commit comments

Comments
 (0)