Extended search drops any query term that contains a line break
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript
- Ambito
- search
Direzione di ricerca
Inizia con le 16 espressioni regolari di rilevamento in src/search/extended/matchers.ts e confronta il loro comportamento con gli esempi di interruzione di riga nell’issue. Aggiungi un test di regressione per un termine tra virgolette contenente un’interruzione di riga e per la query AND, quindi verifica che il termine tra virgolette trovi “The Lock\nArtist” e che la query AND non restituisca risultati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is there an existing issue for this?
- I have searched the existing issues
Description of the bug
With useExtendedSearch: true, a query term that contains a line break (\n, \r, U+2028 or U+2029) is thrown away. It is not searched at all.
This is the same bug as #696. That issue and its PR #697 were closed by the stale bot in 2023 and the bug is still there on main (edf2fb6, 7.6.0-beta.0).
The cause is in src/search/extended/matchers.ts. All 16 detection regexes use (.*) without the s flag. In JavaScript . does not match a line break. So a term with a line break matches none of the regexes, not even the catch-all fuzzy one /^(.*)$/. parseQuery() then pushes no matcher for it, and the term is gone.
This gives wrong results in two ways:
- a query that is only that term finds nothing, even when an item is equal to it
- in an AND query the term is skipped, so items that do not contain it are returned
A tab inside a term already works, because . matches a tab. Only line breaks are lost.
The Fuse.js version where this bug is happening.
Other (please specify in description): 7.6.0-beta.0 (current main). #696 reported it on 6.6.2.
Is this a regression?
No.
Steps To Reproduce
import Fuse from 'fuse.js'
const books = [
{ title: "Old Man's War" },
{ title: 'The Lock\nArtist' },
{ title: 'Artist for Life' }
]
const search = (q, ext) =>
new Fuse(books, { keys: ['title'], useExtendedSearch: ext, threshold: 0.3 })
.search(q)
.map((r) => r.item.title)
console.log(search('\'"Lock\nArtist"', true)) // []
console.log(search("'Lock\nArtist", true)) // []
console.log(search('Lock\nArtist', true)) // []
console.log(search('Lock\nArtist', false)) // [ 'The Lock\nArtist' ]
console.log(search('Lock\nArtist war', true)) // [ "Old Man's War" ]
The last query asks for items that match Lock\nArtist AND war. It returns "Old Man's War", because the first term was dropped.
Expected behavior
A term with a line break should be searched like any other term, as basic search does. '"Lock\nArtist" and 'Lock\nArtist should find "The Lock\nArtist". Lock\nArtist war should find nothing here.
A small fix is to add the s flag to the 16 regexes, as #696 suggested. The build target is ES2020, so the flag is supported. Then a line break is kept inside the term, the same way a tab is today. I can open a PR with that and a test.
One open question for you: the docs say white space acts as AND. If you would rather have an unquoted line break split terms like a space does, that is a change in tokenize() instead. Quoted terms like '"Lock\nArtist" would still need the s flag.
Validated with Claude Opus 5.5.
- Lingua principale
- JavaScript
- Stelle
- 20.5k
- Fork
- 828
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di krisk/Fuse
-
Broken author urlForse già presa @Doomguy-BFG9000 l’ha presa 11 giorni fa. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
-
0.3.14: pdfmake.virtualfs renamed to sharedVirtualfs without changelog entry (breaking change)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
area:mcp
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno