Skip to content

fix(postgrest-js): escape reserved characters in in() and array filters - #2741

Open
mandar1045 wants to merge 1 commit into
supabase:masterfrom
mandar1045:fix/postgrest-filter-escaping
Open

mandar1045 wants to merge 1 commit into
supabase:masterfrom
mandar1045:fix/postgrest-filter-escaping

Conversation

@mandar1045

Copy link
Copy Markdown

Fixes #2740

Filter values with a " or \ were quoted but not escaped, and contains/containedBy/overlaps array elements weren't quoted at all — so the query silently matched the wrong rows. e.g. in('name', ['x,"y']) sent name=in.("x,"y"), which PostgREST reads as two values.

Escape " and \ inside quoted values, quote on those characters too, and quote array elements containing reserved characters. Added tests; verified round-trip against a real PostgREST.

Filter values containing a double quote or backslash were quoted but not
escaped, and contains/containedBy/overlaps array elements were not quoted at
all. That produced malformed filters that silently matched the wrong rows, e.g.
in('name', ['x,"y']) sent name=in.("x,"y") which PostgREST reads as two values.

Escape " and \ inside quoted values, quote on those characters too, and quote
array elements that contain reserved characters.

Fixes supabase#2740
@mandar1045
mandar1045 requested review from a team as code owners October 6, 2026 13:50
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9958b4bb-a306-4bf9-9da4-4585c5aa9756
📥 Commits

Reviewing files that changed from the base of the PR and between 4d23055 and 7199cbf.

📒 Files selected for processing (2)
  • packages/core/postgrest-js/src/PostgrestFilterBuilder.ts
  • packages/core/postgrest-js/test/filter-escaping.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved filtering for values containing special characters, including commas, braces, parentheses, double quotes, and backslashes.
    • Array-based filters now correctly quote and escape string values when needed.

Walkthrough

The filter builder now escapes embedded double quotes and backslashes in quoted values for in and notIn. It also quotes reserved string elements in array values for contains, containedBy, and overlaps. Tests cover these formatting cases and unquoted values without reserved characters.

Assessment against linked issues

Objective Addressed Explanation
Correctly escape quoted values and format reserved array elements in filters [#2740] ✅

Priority: ➖ Normal

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 7199c

The change addresses quoted and reserved characters in filter values. No actionable blocker is established; proceed with normal checks.

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

.in() and .contains() return wrong rows for values with quotes, backslashes, or commas

1 participant