Skip to content

Fix CSV request parsing to skip policy type prefix and trim whitespace#15

Open
Copilot wants to merge 5 commits intomasterfrom
copilot/fix-incorrect-arguments-bug
Open

Fix CSV request parsing to skip policy type prefix and trim whitespace#15
Copilot wants to merge 5 commits intomasterfrom
copilot/fix-incorrect-arguments-bug

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 13, 2025

The plugin incorrectly passed policy type prefixes (p, g, etc.) from CSV lines as request arguments, causing "expected N arguments but received N+1" errors when evaluating requests against the model definition.

Changes

  • Added conditional policy prefix detection: Skip first field if it matches ^(p|g\d*)$ pattern
  • Trim whitespace from all fields: Handle CSV formatting with spaces after commas
  • Extracted extractRequestValues() helper: Consolidates field processing logic from process() and onNewContent()

Example

For model r = sub, obj, act expecting 3 arguments:

// Before: passes ["p", "alice", "data2", "read"] → 4 arguments, error
// After:  passes ["alice", "data2", "read"] → 3 arguments, correct

// Input: "p, alice, data2, read"
extractRequestValues(record.fieldList)
// Returns: ["alice", "data2", "read"]

// Also handles: "alice, data2, read" (no prefix)
// Returns: ["alice", "data2", "read"]

Supports both formats users might reasonably enter in the request editor.

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:

  • cache-redirector.jetbrains.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=256m (dns block)
  • www.jetbrains.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -XX:MaxMetaspaceSize=256m (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>[bug] Reports incorrect arguments</issue_title>
<issue_description>I will use the RBAC example from casbin like

Model:

[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

and Policy:

p, alice, data1, read
p, bob, data2, write
p, data2_admin, data2, read
p, data2_admin, data2, write
g, alice, data2_admin

if I evaluate request:
alice, data2, read

i will get an error saying it expected 3 arguments but received 4, but no error on https://casbin.org/editor (source code: https://github.com/casbin/casbin-editor)

build: Build #WS-251.25410.117, built on May 7, 2025
Version: webstorm 2025.1.1</issue_description>

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


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits December 13, 2025 15:15
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
@hsluoyz hsluoyz marked this pull request as ready for review December 13, 2025 15:21
Copilot AI changed the title [WIP] Fix reports incorrect arguments in RBAC evaluation Fix CSV request parsing to skip policy type prefix and trim whitespace Dec 13, 2025
Copilot AI requested a review from hsluoyz December 13, 2025 15:23
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] Reports incorrect arguments

2 participants