Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add JsonToArray with tests
Add JsonToArray function with corresponding tests.
Using linux instead of windows to solve the problem of line break recognition, thus the test did not report an error.
  • Loading branch information
zhuyanhuazhuyanhua committed Jun 6, 2025
commit b844aedafd5fa53b896921386354c5b2672f8c9e
22 changes: 11 additions & 11 deletions enforcer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func TestLinkConditionFunc(t *testing.T) {
testDomainEnforce(t, e, "alice", "domain5", "data5", "write", false)
}

func TestABACWithJsonArray(t *testing.T){
func TestABACWithJsonArray(t *testing.T) {
modelContent := `
[request_definition]
r = sub, obj, act
Expand All @@ -748,13 +748,13 @@ func TestABACWithJsonArray(t *testing.T){
[matchers]
m = r.sub == p.sub && (r.obj[0] == p.obj || r.obj[1] == p.obj) && r.act == p.act
`
m, err := model.NewModelFromString(modelContent)
if err != nil {
t.Fatalf("Failed to create model: %v", err)
}
e, err := NewEnforcer(m)
if err != nil {
t.Fatalf("Failed to create enforcer: %v", err)
}
e.EnableAcceptJsonRequest(true)
}
m, err := model.NewModelFromString(modelContent)
if err != nil {
t.Fatalf("Failed to create model: %v", err)
}
e, err := NewEnforcer(m)
if err != nil {
t.Fatalf("Failed to create enforcer: %v", err)
}
e.EnableAcceptJsonRequest(true)
}
1 change: 1 addition & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func JsonToArray(jsonStr string) ([]interface{}, error) {
}
return arr, nil
}

// EscapeAssertion escapes the dots in the assertion, because the expression evaluation doesn't support such variable names.
func EscapeAssertion(s string) string {
s = escapeAssertionRegex.ReplaceAllStringFunc(s, func(m string) string {
Expand Down