1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Search: Added further backslash handling

Added due to now not being able to perform an exact search where
contains a trailing backslash.
Now all backslashes in exact terms are consided escape chars
and require escaping themselves.
Potential breaking change due to search syntax handling change.

Related to #4535.
This commit is contained in:
Dan Brown
2023-09-23 13:41:10 +01:00
parent fb417828a4
commit f77bb01b51
4 changed files with 35 additions and 12 deletions

View File

@ -466,10 +466,10 @@ class EntitySearchTest extends TestCase
$search = $this->asEditor()->get('/search?term=' . urlencode('\\\\cat\\dog'));
$search->assertSee($page->getUrl(), false);
$search = $this->asEditor()->get('/search?term=' . urlencode('"\\dog\\"'));
$search = $this->asEditor()->get('/search?term=' . urlencode('"\\dog\\\\"'));
$search->assertSee($page->getUrl(), false);
$search = $this->asEditor()->get('/search?term=' . urlencode('"\\badger\\"'));
$search = $this->asEditor()->get('/search?term=' . urlencode('"\\badger\\\\"'));
$search->assertDontSee($page->getUrl(), false);
$search = $this->asEditor()->get('/search?term=' . urlencode('[\\Categorylike%\\fluffy]'));

View File

@ -20,9 +20,9 @@ class SearchOptionsTest extends TestCase
public function test_from_string_properly_parses_escaped_quotes()
{
$options = SearchOptions::fromString('"\"cat\"" surprise "\"\"" "\"donkey" "\""');
$options = SearchOptions::fromString('"\"cat\"" surprise "\"\"" "\"donkey" "\"" "\\\\"');
$this->assertEquals(['"cat"', '""', '"donkey', '"'], $options->exacts);
$this->assertEquals(['"cat"', '""', '"donkey', '"', '\\'], $options->exacts);
}
public function test_to_string_includes_all_items_in_the_correct_format()
@ -40,13 +40,13 @@ class SearchOptionsTest extends TestCase
}
}
public function test_to_string_escapes_quotes_as_expected()
public function test_to_string_escapes_as_expected()
{
$options = new SearchOptions();
$options->exacts = ['"cat"', '""', '"donkey', '"'];
$options->exacts = ['"cat"', '""', '"donkey', '"', '\\', '\\"'];
$output = $options->toString();
$this->assertEquals('"\"cat\"" "\"\"" "\"donkey" "\""', $output);
$this->assertEquals('"\"cat\"" "\"\"" "\"donkey" "\"" "\\\\" "\\\\\""', $output);
}
public function test_correct_filter_values_are_set_from_string()