Skip to content

Match tabs and line breaks in string.IsNullOrWhiteSpace() queries - #5760

Merged
jeremydmiller merged 1 commit into
JasperFx:masterfrom
johnkaram02:fix-isnullorwhitespace-tabs-newlines
Oct 26, 2026
Merged

jeremydmiller merged 1 commit into
JasperFx:masterfrom
johnkaram02:fix-isnullorwhitespace-tabs-newlines

Conversation

@johnkaram02

Copy link
Copy Markdown
Contributor

Fixes #5759

Problem

string.IsNullOrWhiteSpace(x.Member) in a LINQ Where() is translated to trim(member) = ''. PostgreSQL trim() removes only spaces, so a member that holds only tabs or line breaks (for example "\t" or "\r\n") is not matched, and !string.IsNullOrWhiteSpace(...) returns it.

Change

  • StringIsNullOrWhiteSpace now emits member ~ '^\s*$'. \s matches spaces, tabs, line breaks, form feeds and vertical tabs.
  • New test LinqTests.Bugs.is_null_or_white_space_matches_all_whitespace covers "\t", "\r\n", " \n " and "\f\v", for both the positive and the negated query.

Testing

  • The new test fails on master (4 of 4) and passes with the change (4 of 4).
  • LinqTests on net10.0: 1647 passed, 0 failed.

PostgreSQL trim() strips only spaces, so a member holding only tabs or
line breaks was not treated as null or white space. Match the value
against ^\s*$ instead.
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.

string.IsNullOrWhiteSpace() in LINQ misses values that hold only tabs or line breaks

2 participants