Skip to content

feat: fix 'in' operator parsing for tuple literals in matcher expressions#499

Merged
hsluoyz merged 3 commits intomasterfrom
copilot/fix-jcasbin-matchers-syntax-error
Jan 7, 2026
Merged

feat: fix 'in' operator parsing for tuple literals in matcher expressions#499
hsluoyz merged 3 commits intomasterfrom
copilot/fix-jcasbin-matchers-syntax-error

Conversation

Copy link
Contributor

Copilot AI commented Jan 7, 2026

jCasbin failed to parse in operator expressions with tuple literals like r.obj in ('data2', 'data3'), throwing syntax errors. The regex pattern couldn't handle commas, single quotes, or spaces within parentheses.

Changes

  • Updated regex pattern from ([a-zA-Z0-9_.()\"]*) +in +([a-zA-Z0-9_.()\"]*) to ([^\s]+?) +in +(\([^)]*\)|\S+) to match parenthesized expressions and handle tuple syntax

  • Added smart tuple conversion in replaceInSyntaxWithInclude(): converts comma-separated parenthesized expressions to AviatorScript's tuple() function, while preserving single values and variables

  • Added comprehensive test coverage for tuple literals with various quote styles, multiple in operators, and edge cases

Example

// Before: Syntax error
"r.obj in ('data2', 'data3')"

// After: Converts to valid AviatorScript
"include(tuple('data2', 'data3'), r.obj)"

The conversion logic checks for commas to distinguish tuple literals from parenthesized values:

  • ('data2', 'data3')tuple('data2', 'data3')
  • ("bob")("bob") (preserved)
  • someArraysomeArray (preserved)
Original prompt

This section details on the original issue you should resolve

<issue_title>'in' of matcher</issue_title>
<issue_description>model.conf:

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, obj, act

[role_definition]
g = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act || r.obj in ('data2', 'data3')

OK in Node-Casbin:

Image

But in jcasbin:

Syntax error: invalid token at 64, lineNumber: 1, token : [type='Char',lexeme=',',index=64],
while parsing expression: `
g(r_sub, p_sub) && r_obj == p_obj && r_act == p_act || include((,^^^
`
, error: exit status 1

Image</issue_description>

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

@hsluoyz @lonelyxmas can you share the Casbin editor link? (click "SHARE" button)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@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.

@hsluoyz hsluoyz marked this pull request as ready for review January 7, 2026 08:38
@codecov-commenter
Copy link

codecov-commenter commented Jan 7, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 67.92%. Comparing base (b334732) to head (5cda428).

Files with missing lines Patch % Lines
src/main/java/org/casbin/jcasbin/util/Util.java 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #499   +/-   ##
=======================================
  Coverage   67.91%   67.92%           
=======================================
  Files          63       63           
  Lines        3079     3083    +4     
  Branches      573      574    +1     
=======================================
+ Hits         2091     2094    +3     
  Misses        805      805           
- Partials      183      184    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI and others added 2 commits January 7, 2026 08:41
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix syntax error in jcasbin matcher expression Fix 'in' operator parsing for tuple literals in matcher expressions Jan 7, 2026
Copilot AI requested a review from hsluoyz January 7, 2026 08:50
@hsluoyz hsluoyz changed the title Fix 'in' operator parsing for tuple literals in matcher expressions feat: fix 'in' operator parsing for tuple literals in matcher expressions Jan 7, 2026
@hsluoyz hsluoyz merged commit 14b68c7 into master Jan 7, 2026
1 of 2 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.

[bug] 'in' of matcher doesn't work: "m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act || r.obj in ('data2', 'data3')"

4 participants