Skip to content

Commit

Permalink
chore(*): Upgrade Crates, Increase version to 0.10
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jolhoeft committed Jun 7, 2017
1 parent 9c08945 commit 8d5a7d0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
13 changes: 6 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "nickel"
version = "0.9.0"
version = "0.10.0"
authors = [ "Christoph Burgdorf <[email protected]>",
"Kevin Butler <[email protected]>",
"Simon Persson <[email protected]>" ]
Expand All @@ -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]]
Expand Down
2 changes: 1 addition & 1 deletion src/router/into_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl From<String> 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);
Expand Down
45 changes: 27 additions & 18 deletions src/router/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,25 @@ impl<D> Router<D> {
}

fn extract_params<D>(route: &Route<D>, 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<D> HttpRouter<D> for Router<D> {
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 8d5a7d0

Please sign in to comment.