Extended search drops any query term that contains a line break

Aperta Adatta ai principianti
#862 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@goranai ci sta già lavorando.

Dal 18/11/2026.

  • #863 di @goranai — aperta

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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di krisk/Fuse

Tutte le issue di krisk/Fuse

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.