Skip to content

Commit 2c457d0

Browse files
authored
fix: non-ASCII URLs can be properly routed now (#561)
1 parent ab6ece2 commit 2c457d0

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

cot/src/router/path.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ impl PathMatcher {
3131
let mut state = State::Literal { start: 0 };
3232

3333
let mut char_iter = path_pattern
34-
.chars()
35-
.map(Some)
36-
.chain([None])
37-
.enumerate()
34+
.char_indices()
35+
.map(|(i, c)| (i, Some(c)))
36+
.chain(std::iter::once((path_pattern.len(), None)))
3837
.peekable();
3938
while let Some((index, ch)) = char_iter.next() {
4039
match (ch, state) {
@@ -512,4 +511,19 @@ mod tests {
512511
"/users/123/posts/456"
513512
);
514513
}
514+
515+
#[test]
516+
fn non_ascii_path_pattern() {
517+
let path_parser = PathMatcher::new("/café/{id}");
518+
let mut params = ReverseParamMap::new();
519+
params.insert("id", "123");
520+
assert_eq!(path_parser.reverse(&params).unwrap(), "/café/123");
521+
}
522+
523+
#[test]
524+
fn non_ascii_path_literal() {
525+
let path_parser = PathMatcher::new("/café/test");
526+
let params = ReverseParamMap::new();
527+
assert_eq!(path_parser.reverse(&params).unwrap(), "/café/test");
528+
}
515529
}

0 commit comments

Comments
 (0)