Skip to content

fix(db): LIKE wildcards % and _ should match newline characters#407

Open
sravan27 wants to merge 1 commit into
aspen-cloud:mainfrom
sravan27:fix/like-newline-dotall
Open

fix(db): LIKE wildcards % and _ should match newline characters#407
sravan27 wants to merge 1 commit into
aspen-cloud:mainfrom
sravan27:fix/like-newline-dotall

Conversation

@sravan27

Copy link
Copy Markdown

Summary

like/nlike filters compile the SQL pattern to a RegExp without the dotall
(s) flag (packages/db/src/filters.ts, ilike()), so the % (→ .*) and _
(→ .) wildcards don't match newline characters. This diverges from SQL LIKE,
where % matches any sequence and _ any single character — newlines included.
A stored value containing a newline is silently excluded from patterns it
should match.

Reproduce (before this PR)

'a\nb'        LIKE 'a%b'  ->  false   (SQL: true)
'a\nb'        LIKE 'a_b'  ->  false   (SQL: true)
'multi\nline' LIKE '%'    ->  false   (SQL: true)

Fix

Add the s (dotall) flag to the compiled regex. JS $ (without the m flag)
already anchors to the true end of the string, so there is no trailing-newline
false positive — only the missing matches needed fixing.

Tests

The like/nlike suites were describe.todo placeholders (with a TODO: move over like/nlike tests note), so this behaviour was shipping untested. Replaced
them with regression coverage for newline handling, using the existing
testFilterOp harness. The wildcard→regex mapping was also cross-checked against
SQL semantics with a small reference script: the current implementation diverges
on the newline cases; with the s flag it matches on all cases (no regression on
the existing non-newline behaviour).

Opened as a draft pending a CI run of the db test suite.

`ilike()` compiled the LIKE pattern to a RegExp without the dotall flag, so
`%` (-> .*) and `_` (-> .) did not match newline characters. This diverges from
SQL LIKE semantics, where `%` matches any sequence and `_` any single character,
newlines included — silently excluding rows whose value contains a newline
(e.g. 'a\nb' did not match 'a%b').

Add the `s` flag and enable the previously `describe.todo` like/nlike suites
with regression coverage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented May 29, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Aspen Cloud Team on Vercel.

A member of the Team first needs to authorize it.

@sravan27 sravan27 marked this pull request as ready for review May 29, 2026 14:08
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.

1 participant