Extended search drops any query term that contains a line break
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript
- Domain
- search
Research direction
Start with the 16 detection regexes in src/search/extended/matchers.ts and compare their behavior with the line-break examples in the issue. Add a regression test for a quoted term containing a line break and for the AND query, then check that the quoted term finds “The Lock\nArtist” and the AND query returns no results.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- JavaScript
- Stars
- 20.5k
- Forks
- 828
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from krisk/Fuse
-
Broken author urlPossibly taken @Doomguy-BFG9000 claimed this 11 days ago. Openbug
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
area:mcp
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day