mirror of
https://github.com/simonw/datasette.git
synced 2026-10-18 15:26:57 +02:00
Merge 0b61c76b25 into c435a80030
This commit is contained in:
commit
6053ece396
3 changed files with 16 additions and 1 deletions
|
|
@ -1142,7 +1142,7 @@ def format_bytes(bytes):
|
|||
return f"{current:.1f} {unit}"
|
||||
|
||||
|
||||
_escape_fts_re = re.compile(r'\s+|(".*?")')
|
||||
_escape_fts_re = re.compile(r'\s+|(".*?")', re.DOTALL)
|
||||
|
||||
|
||||
def escape_fts(query):
|
||||
|
|
|
|||
|
|
@ -562,6 +562,16 @@ async def test_searchable(ds_client, path, expected_rows):
|
|||
assert expected_rows == response.json()["rows"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_search_quote_followed_by_newline(ds_client):
|
||||
# A quote followed by a newline used to produce an invalid FTS query
|
||||
response = await ds_client.get(
|
||||
"/fixtures/searchable.json?_shape=arrays&_search=e%22%0A%21"
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["rows"] == []
|
||||
|
||||
|
||||
_SEARCHMODE_RAW_RESULTS = [
|
||||
[1, "barry cat", "terry dog", "panther"],
|
||||
[2, "terry dog", "sara weasel", "puma"],
|
||||
|
|
|
|||
|
|
@ -605,6 +605,11 @@ def test_format_bytes(bytes, expected):
|
|||
# Sensibly handle unbalanced double quotes
|
||||
('cat"', '"cat"'),
|
||||
('"cat dog" "fish', '"cat dog" "fish"'),
|
||||
# Quoted phrases and unbalanced quotes can contain newlines
|
||||
('"cat\ndog"', '"cat\ndog"'),
|
||||
('"cat\ndog" fish', '"cat\ndog" "fish"'),
|
||||
('cat "dog\nfish', '"cat" "dog\nfish"'),
|
||||
('cat"\n!', '"cat" "\n!"'),
|
||||
],
|
||||
)
|
||||
def test_escape_fts(query, expected):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue