1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-18 14:16:47 +00:00

Support for unnamed regex groups in route params

Adds support for unnamed groups in route regexs
This commit is contained in:
Kim Christensen 2018-07-15 21:33:05 +02:00
parent 3373847a14
commit e0dc93b628

View file

@ -706,7 +706,7 @@ impl ResourceDef {
len = 0;
in_param_pattern = false;
in_param = false;
} else if ch == ':' {
} else if ch == ':' && !in_param_pattern {
// The parameter name has been determined; custom pattern land
in_param_pattern = true;
param_pattern.clear();
@ -934,6 +934,26 @@ mod tests {
let info = re.match_with_params(&req, 0).unwrap();
assert_eq!(info.get("version").unwrap(), "151");
assert_eq!(info.get("id").unwrap(), "adahg32");
let re = ResourceDef::new("/v{version:[0-9]+}/resource/{id}");
assert!(re.is_match("/v1/resource/320120"));
assert!(!re.is_match("/v/resource/1"));
assert!(!re.is_match("/va/resource/1"));
let req = TestRequest::with_uri("/v151/resource/adahg32").finish();
let info = re.match_with_params(&req, 0).unwrap();
assert_eq!(info.get("version").unwrap(), "151");
assert_eq!(info.get("id").unwrap(), "adahg32");
let re = ResourceDef::new("/v{version:(?:[0-9])+}/resource/{id}");
assert!(re.is_match("/v1/resource/320120"));
assert!(!re.is_match("/v/resource/1"));
assert!(!re.is_match("/va/resource/1"));
let req = TestRequest::with_uri("/v151/resource/adahg32").finish();
let info = re.match_with_params(&req, 0).unwrap();
assert_eq!(info.get("version").unwrap(), "151");
assert_eq!(info.get("id").unwrap(), "adahg32");
}
#[test]