Skip to content

fix(db): like not matching newline characters#1263

Merged
KyleAMathews merged 4 commits intoTanStack:mainfrom
ldirer:claude/fix-ilike-newline-matching-73gpb
Feb 18, 2026
Merged

fix(db): like not matching newline characters#1263
KyleAMathews merged 4 commits intoTanStack:mainfrom
ldirer:claude/fix-ilike-newline-matching-73gpb

Conversation

@ldirer
Copy link
Contributor

@ldirer ldirer commented Feb 18, 2026

Summary

Fix like/ilike operators 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 evaluateLike function converts SQL LIKE patterns to JavaScript regex (%.*, _.), but . in JS regex doesn't match line terminators (\n, \r, \u2028, \u2029) unless the s (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 the RegExp constructor in both copies of evaluateLike:

// Before
const regex = new RegExp(`^${regexPattern}$`)

// After — dotAll flag so '.' matches newline characters (SQL LIKE semantics)
const regex = new RegExp(`^${regexPattern}$`, `s`)

The fix is applied in two locations:

  • packages/db/src/query/compiler/evaluators.ts — the core runtime
  • packages/query-db-collection/e2e/query-filter.ts — the e2e test helper (duplicated logic)

Verification

pnpm vitest run packages/db/tests/query/compiler/evaluators.test.ts

All 180 evaluator tests pass (90 per copy), including 4 new tests covering like and ilike with % and _ against newline characters.

Files Changed

File Change
packages/db/src/query/compiler/evaluators.ts Add s (dotAll) flag to RegExp
packages/query-db-collection/e2e/query-filter.ts Same fix in duplicated e2e helper
packages/db/tests/query/compiler/evaluators.test.ts Add 4 unit tests for like/ilike newline matching
packages/db-collection-e2e/src/fixtures/seed-data.ts Add seed user with newline in name
packages/db-collection-e2e/src/suites/predicates.suite.ts Add e2e test for like with newline
.changeset/nice-months-nail.md Patch changeset for @tanstack/db

🤖 Generated with Claude Code

claude and others added 4 commits February 18, 2026 15:11
Add failing tests that demonstrate % and _ wildcards in like/ilike
do not match across newline characters.
@changeset-bot
Copy link

changeset-bot bot commented Feb 18, 2026

🦋 Changeset detected

Latest commit: 90eea96

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@tanstack/db Patch
@tanstack/angular-db Patch
@tanstack/electric-db-collection Patch
@tanstack/offline-transactions Patch
@tanstack/powersync-db-collection Patch
@tanstack/query-db-collection Patch
@tanstack/react-db Patch
@tanstack/rxdb-db-collection Patch
@tanstack/solid-db Patch
@tanstack/svelte-db Patch
@tanstack/trailbase-db-collection Patch
@tanstack/vue-db Patch

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

@ldirer ldirer changed the title Fix like not matching newline characters fix(db): like not matching newline characters Feb 18, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 18, 2026

More templates

@tanstack/angular-db

npm i https://pkg.pr.new/@tanstack/angular-db@1263

@tanstack/db

npm i https://pkg.pr.new/@tanstack/db@1263

@tanstack/db-ivm

npm i https://pkg.pr.new/@tanstack/db-ivm@1263

@tanstack/electric-db-collection

npm i https://pkg.pr.new/@tanstack/electric-db-collection@1263

@tanstack/offline-transactions

npm i https://pkg.pr.new/@tanstack/offline-transactions@1263

@tanstack/powersync-db-collection

npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1263

@tanstack/query-db-collection

npm i https://pkg.pr.new/@tanstack/query-db-collection@1263

@tanstack/react-db

npm i https://pkg.pr.new/@tanstack/react-db@1263

@tanstack/rxdb-db-collection

npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1263

@tanstack/solid-db

npm i https://pkg.pr.new/@tanstack/solid-db@1263

@tanstack/svelte-db

npm i https://pkg.pr.new/@tanstack/svelte-db@1263

@tanstack/trailbase-db-collection

npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1263

@tanstack/vue-db

npm i https://pkg.pr.new/@tanstack/vue-db@1263

commit: 90eea96

@KyleAMathews KyleAMathews merged commit 4ff3da5 into TanStack:main Feb 18, 2026
7 checks passed
@KyleAMathews
Copy link
Collaborator

Thanks for the fix!

@github-actions github-actions bot mentioned this pull request Feb 18, 2026
@github-actions
Copy link
Contributor

🎉 This PR has been released!

Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants