Skip to content

fix: add keyGet3 function #522

Open
AlabLan wants to merge 1 commit into
apache:masterfrom
AlabLan:keyget3
Open

fix: add keyGet3 function #522
AlabLan wants to merge 1 commit into
apache:masterfrom
AlabLan:keyget3

Conversation

@AlabLan
Copy link
Copy Markdown

@AlabLan AlabLan commented May 14, 2026

Summary

Added the keyGet3 function to jcasbin for the {var} placeholder style, which was previously only available in the Go version.

Problem

The documentation at https://casbin.apache.org/docs/function shows keyGet3 function, but jcasbin only implemented keyGet and keyGet2.

Implementation

  • Added KeyGet3Func wrapper class
  • Added keyGet3Func implementation in BuiltInFunctions
  • Registered keyGet3 in FunctionMap
  • Added comprehensive tests ported from Go's TestKeyGet3

Note on Go/Java Regex Incompatibility

The following Go test cases fail in Java due to regex engine differences:

  • testKeyGet3("/{id/using/myresid", "/{id/using/{resId}", "resId", "myresid")
  • testKeyGet3("/{id/using/myresid/status}", "/{id/using/{resId}/status}", "resId", "myresid")
  • testKeyGet3("/api/group1_group_name/project1_admin/info", "/api/{proj}_admin/info", "proj", "")

Java treats { as a repetition quantifier modifier, so patterns like "/{id/using/(" are invalid. The Java implementation adds escaping for remaining { and } characters after the key replacement to
handle this incompatibility.

@AlabLan AlabLan changed the title bugfix: add keyGet3 function for {var} placeholder style fix: add keyGet3 function May 15, 2026
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.

1 participant