Skip to content

Extended search drops any query term that contains a line break #862

Closed

Description

@goranai

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.

Activity

  1. added a commit that references this issue on Nov 22, 2026
    ce1df04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions