fix(db): like not matching newline characters#1263
Merged
KyleAMathews merged 4 commits intoTanStack:mainfrom Feb 18, 2026
Merged
fix(db): like not matching newline characters#1263KyleAMathews merged 4 commits intoTanStack:mainfrom
KyleAMathews merged 4 commits intoTanStack:mainfrom
Conversation
Add failing tests that demonstrate % and _ wildcards in like/ilike do not match across newline characters.
🦋 Changeset detectedLatest commit: 90eea96 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Collaborator
|
Thanks for the fix! |
Merged
Contributor
|
🎉 This PR has been released! Thank you for your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
like/ilikeoperators not matching newline characters with%or_wildcards. SQL LIKE semantics treat%as matching any sequence of characters (including newlines) and_as matching any single character (including newlines), but JavaScript's RegExp.does not match newline characters by default.Root Cause
The
evaluateLikefunction converts SQL LIKE patterns to JavaScript regex (%→.*,_→.), but.in JS regex doesn't match line terminators (\n,\r,\u2028,\u2029) unless thes(dotAll) flag is set. This meant any field value containing a newline would fail to match patterns that should logically match it.Approach
Add the
s(dotAll) flag to theRegExpconstructor in both copies ofevaluateLike:The fix is applied in two locations:
packages/db/src/query/compiler/evaluators.ts— the core runtimepackages/query-db-collection/e2e/query-filter.ts— the e2e test helper (duplicated logic)Verification
All 180 evaluator tests pass (90 per copy), including 4 new tests covering
likeandilikewith%and_against newline characters.Files Changed
packages/db/src/query/compiler/evaluators.tss(dotAll) flag to RegExppackages/query-db-collection/e2e/query-filter.tspackages/db/tests/query/compiler/evaluators.test.tspackages/db-collection-e2e/src/fixtures/seed-data.tspackages/db-collection-e2e/src/suites/predicates.suite.ts.changeset/nice-months-nail.md🤖 Generated with Claude Code