Skip to content

feat: fix empty string values converted to NULL in PostgreSQL#52

Merged
nomeguy merged 5 commits intomasterfrom
copilot/fix-casbin-empty-string-support
Nov 22, 2025
Merged

feat: fix empty string values converted to NULL in PostgreSQL#52
nomeguy merged 5 commits intomasterfrom
copilot/fix-casbin-empty-string-support

Conversation

Copy link
Contributor

Copilot AI commented Nov 22, 2025

Empty strings in Casbin rules were being converted to NULL in PostgreSQL, making it impossible to distinguish between intentionally empty values and wildcards in filters.

Changes

Database mapping

  • Added pg:",use_zero" tags to V0-V5 fields in CasbinRule struct to prevent go-pg from converting empty strings to NULL

Rule serialization

  • Updated String(), toStringPolicy(), and queryString() methods to preserve empty strings up to the last non-empty value
  • Added getValues() and getLastNonEmptyIndex() helpers to avoid duplicate slice allocations

Behavior

Empty strings in the middle of rules are now preserved:

// Before: stored as NULL, couldn't be matched
e.AddPolicy("alice", "", "read")  // Failed to store/retrieve correctly

// After: stored as empty string, exact match works
e.AddPolicy("alice", "", "read")  
e.RemovePolicy("alice", "", "read")  // ✓ Matches and removes

// Wildcard filtering still works
e.RemoveFilteredPolicy(0, "", "data1")  // ✓ Matches all v0 values

Trailing empty strings are trimmed by Casbin per its design (not changed).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Is casbin seriously not supporting empty string values?</issue_title>
<issue_description>Is casbin seriously not supporting empty string values?
I get [null] in postgres every single time I try to use an empty string
using casbin's official postgres adapter github.com/casbin/casbin-pg-adapter
Seems like a massive issue
What if I want to differentiate between a wildcard and a purposefully omitted value?
It just turns into a [null] and breaks casbin</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@nomeguy nomeguy marked this pull request as ready for review November 22, 2025 08:50
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 4 commits November 22, 2025 08:57
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix casbin to support empty string values in postgres Fix empty string values converted to NULL in PostgreSQL Nov 22, 2025
Copilot AI requested a review from nomeguy November 22, 2025 09:10
@nomeguy nomeguy changed the title Fix empty string values converted to NULL in PostgreSQL feat: fix empty string values converted to NULL in PostgreSQL Nov 22, 2025
@nomeguy nomeguy merged commit ec3af17 into master Nov 22, 2025
7 of 8 checks passed
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.

Is casbin seriously not supporting empty string values?

3 participants