This commit is contained in:
Kim Christensen 2018-08-03 18:57:09 +00:00 committed by GitHub
commit b8e1971972
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 1 deletions

View File

@ -856,7 +856,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();
@ -1084,6 +1084,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]