Skip to content

Commit

Permalink
Merge pull request #52 from Turbo87/chinese
Browse files Browse the repository at this point in the history
Fix char boundary bug
  • Loading branch information
yoshuawuyts authored Oct 25, 2021
2 parents 953e791 + 2bc53c0 commit 64f449d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,4 +554,15 @@ mod tests {
let m = router.recognize("/4.static.static");
assert!(m.is_err());
}

#[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"));
}
}
2 changes: 1 addition & 1 deletion src/nfa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl<T> NFA<T> {
{
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() {
Expand Down

0 comments on commit 64f449d

Please sign in to comment.