This is an automated email from the ASF dual-hosted git repository.
hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin.git
The following commit(s) were added to refs/heads/master by this push:
new 9e2e997 fix: return error instead of panic on missing policy type in
LoadPolicyArray (#1757)
9e2e997 is described below
commit 9e2e9977d8b5c76d601fb516d1f8b419fba29b6f
Author: Zhao Jianing <[email protected]>
AuthorDate: Wed Sep 9 23:50:16 2026 +0800
fix: return error instead of panic on missing policy type in
LoadPolicyArray (#1757)
---
persist/adapter.go | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/persist/adapter.go b/persist/adapter.go
index 8178bde..e0d91cd 100644
--- a/persist/adapter.go
+++ b/persist/adapter.go
@@ -20,6 +20,7 @@ package persist
import (
"bytes"
"encoding/csv"
+ "errors"
"strings"
"github.com/casbin/casbin/v3/model"
@@ -74,6 +75,10 @@ func PolicyLineToCsv(ptype string, rule []string) (string,
error) {
// LoadPolicyArray loads a policy rule to model.
func LoadPolicyArray(rule []string, m model.Model) error {
+ if len(rule) == 0 || rule[0] == "" {
+ return errors.New("invalid policy rule: missing policy type")
+ }
+
key := rule[0]
sec := key[:1]
ok, err := m.HasPolicyEx(sec, key, rule[1:])
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]