1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-29 00:07:48 +02:00

fix router cannot parse Non-ASCII characters in URL #137

This commit is contained in:
Nikolay Kim
2018-03-28 16:10:58 -07:00
parent 4f7d45ee9c
commit 90e3aaaf8a
5 changed files with 46 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ use std::hash::{Hash, Hasher};
use std::collections::HashMap;
use regex::{Regex, escape};
use percent_encoding::percent_decode;
use error::UrlGenerationError;
use param::Params;
@@ -70,9 +71,10 @@ impl Router {
}
let path: &str = unsafe{mem::transmute(&req.path()[self.0.prefix_len..])};
let route_path = if path.is_empty() { "/" } else { path };
let p = percent_decode(route_path.as_bytes()).decode_utf8().unwrap();
for (idx, pattern) in self.0.patterns.iter().enumerate() {
if pattern.match_with_params(route_path, req.match_info_mut()) {
if pattern.match_with_params(p.as_ref(), req.match_info_mut()) {
return Some(idx)
}
}