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-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 908f50c  fix: handle non-ASCII input in key_match and key_get
908f50c is described below

commit 908f50cc39f24a17c9796bd703535c1893375898
Author: Yang Luo <[email protected]>
AuthorDate: Thu Oct 8 02:03:29 2026 +0800

    fix: handle non-ASCII input in key_match and key_get
---
 src/model/function_map.rs | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/model/function_map.rs b/src/model/function_map.rs
index ee828e8..8dfa521 100644
--- a/src/model/function_map.rs
+++ b/src/model/function_map.rs
@@ -203,10 +203,7 @@ pub fn dynamic_to_str(d: &Dynamic) -> Cow<'_, str> {
 /// For example, "/foo/bar" matches "/foo/*"
 pub fn key_match(key1: &str, key2: &str) -> bool {
     if let Some(i) = key2.find('*') {
-        if key1.len() > i {
-            return key1[..i] == key2[..i];
-        }
-        key1[..] == key2[..i]
+        key1.starts_with(&key2[..i])
     } else {
         key1 == key2
     }
@@ -217,7 +214,7 @@ pub fn key_match(key1: &str, key2: &str) -> bool {
 /// "bar/foo" will be returned.
 pub fn key_get(key1: &str, key2: &str) -> String {
     if let Some(i) = key2.find('*') {
-        if key1.len() > i && key1[..i] == key2[..i] {
+        if key1.len() > i && key1.starts_with(&key2[..i]) {
             return key1[i..].to_string();
         }
     }
@@ -441,6 +438,8 @@ mod tests {
         assert!(key_match("/foo/bar", "/foo/*"));
         assert!(!key_match("/bar/foo", "/foo/*"));
         assert!(key_match("/bar", "/ba*"));
+        assert!(!key_match("ééééé", "/foo/*"));
+        assert!(key_match("/éé/bar", "/éé/*"));
     }
 
     #[test]
@@ -454,6 +453,8 @@ mod tests {
         assert_eq!(key_get("/foobar", "/foo"), "");
         assert_eq!(key_get("/foobar", "/foo*"), "bar");
         assert_eq!(key_get("/foobar", "/foo/*"), "");
+        assert_eq!(key_get("ééééé", "/foo/*"), "");
+        assert_eq!(key_get("/éé/bar", "/éé/*"), "bar");
     }
 
     #[test]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to