mirror of
https://github.com/zerotier/ratpack.git
synced 2026-05-22 16:27:23 -07:00
change the spec for the greater good
Signed-off-by: Erik Hollensbe <linux@hollensbe.org>
This commit is contained in:
+11
-4
@@ -21,8 +21,13 @@ impl Ord for Path {
|
||||
impl Path {
|
||||
pub(crate) fn new(path: String) -> Self {
|
||||
let mut parts = Self::default();
|
||||
if !path.contains("/") {
|
||||
return Self::default();
|
||||
}
|
||||
|
||||
for arg in path.split("/") {
|
||||
let args = path.split("/");
|
||||
|
||||
for arg in args {
|
||||
if arg.starts_with(":") {
|
||||
// is param
|
||||
parts.push(RoutePart::Param(arg.trim_start_matches(":").to_string()));
|
||||
@@ -30,7 +35,6 @@ impl Path {
|
||||
// skip empties. this will push additional leaders if there is an duplicate slash
|
||||
// (e.g.: `//one/two`), which will fail on matching; we don't want to support this
|
||||
// syntax in the router.
|
||||
parts.push(RoutePart::Leader);
|
||||
} else {
|
||||
// is not param
|
||||
parts.push(RoutePart::PathComponent(arg.to_string()));
|
||||
@@ -134,7 +138,7 @@ impl PartialEq for Path {
|
||||
|
||||
impl Default for Path {
|
||||
fn default() -> Self {
|
||||
Self(Vec::new())
|
||||
Self(vec![RoutePart::Leader])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +172,7 @@ mod tests {
|
||||
|
||||
let path = Path::new("/abc/def/ghi".to_string());
|
||||
assert!(path.matches("/abc/def/ghi".to_string()));
|
||||
assert!(!path.matches("//abc/def/ghi".to_string()));
|
||||
assert!(path.matches("//abc/def/ghi".to_string()));
|
||||
assert!(!path.matches("/def/ghi".to_string()));
|
||||
assert!(path.params().is_empty());
|
||||
|
||||
@@ -198,5 +202,8 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(Path::default().to_string(), "/".to_string());
|
||||
|
||||
let path = Path::new("/".to_string());
|
||||
assert!(path.matches("/".to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user