Skip to content

[Bug] When there is a comma in the policy, the policy fails to load. #886

Description

@leeqvip

Want to prioritize this issue? Try:

issuehunt-to-marktext


Describe the bug
When there is a comma in the policy, the policy fails to load.

To Reproduce

m, _ := model.NewModelFromFile("examples/rbac_model.conf")
persist.LoadPolicyLine(`p, alice, data, r.act in ("get", "post")`, m)
m.PrintPolicy() // Nothing is printed , it should output `[p alice data r.act in ("get", "post")]`

Additional context
Probably there was a problem in CSV Reader :https://github.com/casbin/casbin/blob/master/persist/adapter.go#L30
Can we provide a method like this :

func LoadPolicy(tokens []string, m model.Model) {
	key := tokens[0]
	sec := key[:1]
	m[sec][key].Policy = append(m[sec][key].Policy, tokens[1:])
	m[sec][key].PolicyMap[strings.Join(tokens[1:], model.DefaultSep)] = len(m[sec][key].Policy) - 1
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions