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 a918daf fix: preserve non-ASCII literals in EscapeStringLiterals
(#1746)
a918daf is described below
commit a918daf3e94137b9fc531a2013e962df0dd34724
Author: Nikolaus Schuetz <[email protected]>
AuthorDate: Sun Aug 2 10:52:39 2026 -0700
fix: preserve non-ASCII literals in EscapeStringLiterals (#1746)
---
util/util.go | 4 +---
util/util_test.go | 5 +++++
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/util/util.go b/util/util.go
index 555d53e..88b001f 100644
--- a/util/util.go
+++ b/util/util.go
@@ -288,9 +288,7 @@ func EscapeStringLiterals(expr string) string {
inString := false
var quote rune
- for i := 0; i < len(expr); i++ {
- ch := rune(expr[i])
-
+ for _, ch := range expr {
if inString {
result.WriteRune(ch)
if ch == '\\' {
diff --git a/util/util_test.go b/util/util_test.go
index 3f33f76..201fa0c 100644
--- a/util/util_test.go
+++ b/util/util_test.go
@@ -257,6 +257,11 @@ func TestEscapeStringLiterals(t *testing.T) {
testEscapeStringLiterals(t, `regexMatch("\1\2", p.obj)`,
`regexMatch("\\1\\2", p.obj)`)
testEscapeStringLiterals(t, `r.sub == '\test'`, `r.sub == '\\test'`)
+ // Test that non-ASCII (multi-byte UTF-8) string literals are preserved
+ testEscapeStringLiterals(t, `r.sub == '香港'`, `r.sub == '香港'`)
+ testEscapeStringLiterals(t, `r.obj == "café"`, `r.obj == "café"`)
+ testEscapeStringLiterals(t, `keyMatch(r.obj, 'naïve\1')`,
`keyMatch(r.obj, 'naïve\\1')`)
+
// Test expressions without string literals
testEscapeStringLiterals(t, `r.sub == p.sub`, `r.sub == p.sub`)
testEscapeStringLiterals(t, `keyMatch(r.obj, p.obj)`, `keyMatch(r.obj,
p.obj)`)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]