From 519473f18b5287a3131f5c2807db6b31c42add4a Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Tue, 19 Oct 2021 17:43:38 +0200 Subject: [PATCH] Fix char boundary bug --- src/lib.rs | 11 +++++++++++ src/nfa.rs | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index eb7c957..6256297 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -571,4 +571,15 @@ mod tests { "Hello" ); } + + #[test] + fn test_chinese() { + let mut router = Router::new(); + router.add("/crates/:foo/:bar", "Hello".to_string()); + + let m = router.recognize("/crates/实打实打算/d's'd").unwrap(); + assert_eq!(m.handler().as_str(), "Hello"); + assert_eq!(m.params().find("foo"), Some("实打实打算")); + assert_eq!(m.params().find("bar"), Some("d's'd")); + } } diff --git a/src/nfa.rs b/src/nfa.rs index a7db716..7d6df04 100644 --- a/src/nfa.rs +++ b/src/nfa.rs @@ -227,7 +227,7 @@ impl NFA { { let mut threads = vec![Thread::new()]; - for (i, char) in string.chars().enumerate() { + for (i, char) in string.char_indices() { let next_threads = self.process_char(threads, char, i); if next_threads.is_empty() {