When EnableAcceptJsonRequest(true) is enabled, passing a valid JSON string as a parameter to Enforce() fails if the matcher attempts to access a field within that JSON object (e.g., r.sub.Name). The enforcer returns an error indicating that the parameter is not a struct or map, implying that the JSON string was not automatically parsed into an object before evaluation.
To Reproduce
Reproduction code:
func TestReproduce(t *testing.T) {
modelText := `
[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 = r.sub.Name == "\x20"
`
m, err := model.NewModelFromString(modelText)
if err != nil {
t.Fatalf("Failed to create model: %v", err)
}
e, err := NewEnforcer(m)
if err != nil {
fmt.Printf("Error: %v\n", err)
}
dataJSON := `{"Name": "\x20"}`
e.EnableAcceptJsonRequest(true)
res, err := e.Enforce(dataJSON, true, "read")
fmt.Printf("result: %v, err: %v\n", res, err) -> “result: false, err: Unable to access 'Name', 'r_sub' is not a struct or map”
}
And I also try to reproduce it in editor. However, the editor return false without any error. Their behaviours are inconsistent as well. https://editor.casbin.org/#ETVDB3RF7