From 8d5a7d0515dab850d88249f392db8db463437068 Mon Sep 17 00:00:00 2001 From: Jeff Olhoeft Date: Sat, 13 May 2017 01:46:09 -0700 Subject: [PATCH] chore(*): Upgrade Crates, Increase version to 0.10 regex 0.1 -> 0.2 mustache 0.6 -> 0.8 hyper 0.9 -> 0.10 lazy_static 0.1 -> 0.2 compiletest_rs 0.1 -> 0.2 Note: since hyper removed ssl support, nickel no longer has it --- Cargo.toml | 13 +++++------ src/router/into_matcher.rs | 2 +- src/router/router.rs | 45 +++++++++++++++++++++++--------------- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a2bc2c85f4..692e4c7a14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "nickel" -version = "0.9.0" +version = "0.10.0" authors = [ "Christoph Burgdorf ", "Kevin Butler ", "Simon Persson " ] @@ -14,27 +14,26 @@ keywords = ["nickel", "server", "web", "express"] [features] unstable = ["hyper/nightly", "compiletest_rs"] -ssl = ["hyper/ssl"] [dependencies] url = "1.0" time = "0.1" typemap = "0.3" plugin = "0.2" -regex = "0.1" +regex = "0.2" rustc-serialize = "0.3" log = "0.3" groupable = "0.2" -mustache = "0.6" -lazy_static = "0.1" +mustache = "0.8" +lazy_static = "0.2" modifier = "0.1" [dependencies.hyper] -version = "0.9" +version = "0.10" default-features = false [dependencies.compiletest_rs] -version = "0.1" +version = "0.2" optional = true [[example]] diff --git a/src/router/into_matcher.rs b/src/router/into_matcher.rs index 397c369399..eaeaed93b8 100644 --- a/src/router/into_matcher.rs +++ b/src/router/into_matcher.rs @@ -49,7 +49,7 @@ impl From for Matcher { let named_captures = REGEX_VAR_SEQ.replace_all(&wildcarded, |captures: &Captures| { // There should only ever be one match (after subgroup 0) let c = captures.iter().skip(1).next().unwrap(); - format!("(?P<{}>[,a-zA-Z0-9%_-]*)", c.unwrap()) + format!("(?P<{}>[,a-zA-Z0-9%_-]*)", c.unwrap().as_str()) }); let line_regex = format!("^{}{}$", named_captures, REGEX_PARAM_SEQ); diff --git a/src/router/router.rs b/src/router/router.rs index 25729de004..d1968e8b3b 100644 --- a/src/router/router.rs +++ b/src/router/router.rs @@ -70,16 +70,25 @@ impl Router { } fn extract_params(route: &Route, path: &str) -> Vec<(String, String)> { - match route.matcher.captures(path) { - Some(captures) => { - captures.iter_named() - .filter_map(|(name, subcap)| { - subcap.map(|cap| (name.to_string(), cap.to_string())) - }) - .collect() - } - None => vec![] - } + let captures = match route.matcher.captures(path) { + Some(cap) => cap, + None => { return vec![]; }, + }; + route.matcher.capture_names() + .filter_map(|n| { + let name = if let Some(name) = n { + name + } else { + return None; + }; + let capture = if let Some(capture) = captures.name(name) { + capture + } else { + return None; + }; + Some((name.to_string(), capture.as_str().to_string())) + }) + .collect() } impl HttpRouter for Router { @@ -124,29 +133,29 @@ fn creates_regex_with_captures () { let caps = matcher.captures("foo/4711/bar/5490").unwrap(); assert_eq!(matcher.path(), "foo/:uid/bar/:groupid(\\.:format)?"); - assert_eq!(caps.at(1).unwrap(), "4711"); - assert_eq!(caps.at(2).unwrap(), "5490"); + assert_eq!(caps.get(1).unwrap().as_str(), "4711"); + assert_eq!(caps.get(2).unwrap().as_str(), "5490"); let matcher: Matcher = "foo/*/:uid/bar/:groupid".into(); let caps = matcher.captures("foo/test/4711/bar/5490").unwrap(); assert_eq!(matcher.path(), "foo/*/:uid/bar/:groupid(\\.:format)?"); - assert_eq!(caps.at(1).unwrap(), "4711"); - assert_eq!(caps.at(2).unwrap(), "5490"); + assert_eq!(caps.get(1).unwrap().as_str(), "4711"); + assert_eq!(caps.get(2).unwrap().as_str(), "5490"); let matcher: Matcher = "foo/**/:uid/bar/:groupid".into(); let caps = matcher.captures("foo/test/another/4711/bar/5490").unwrap(); assert_eq!(matcher.path(), "foo/**/:uid/bar/:groupid(\\.:format)?"); - assert_eq!(caps.at(1).unwrap(), "4711"); - assert_eq!(caps.at(2).unwrap(), "5490"); + assert_eq!(caps.get(1).unwrap().as_str(), "4711"); + assert_eq!(caps.get(2).unwrap().as_str(), "5490"); let matcher: Matcher = "foo/**/:format/bar/:groupid".into(); let caps = matcher.captures("foo/test/another/4711/bar/5490").unwrap(); assert_eq!(matcher.path(), "foo/**/:format/bar/:groupid"); - assert_eq!(caps.name("format").unwrap(), "4711"); - assert_eq!(caps.name("groupid").unwrap(), "5490"); + assert_eq!(caps.name("format").unwrap().as_str(), "4711"); + assert_eq!(caps.name("groupid").unwrap().as_str(), "5490"); } #[test]