From ebfd3ac2755e0607c73d95e87dcc3de7efada87a Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 2 Dec 2017 10:43:14 -0800 Subject: [PATCH] tests for PathBuf::from_param --- src/recognizer.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/recognizer.rs b/src/recognizer.rs index b5c8ea9e..7aac944c 100644 --- a/src/recognizer.rs +++ b/src/recognizer.rs @@ -129,8 +129,8 @@ impl FromParam for PathBuf { return Err(UriSegmentError::BadEnd('>')) } else if segment.ends_with('<') { return Err(UriSegmentError::BadEnd('<')) - } else if segment.contains('/') { - return Err(UriSegmentError::BadChar('/')) + } else if segment.is_empty() { + continue } else if cfg!(windows) && segment.contains('\\') { return Err(UriSegmentError::BadChar('\\')) } else { @@ -347,6 +347,20 @@ fn parse(pattern: &str) -> String { mod tests { use regex::Regex; use super::*; + use std::iter::FromIterator; + + #[test] + fn test_path_buf() { + assert_eq!(PathBuf::from_param("/test/.tt"), Err(UriSegmentError::BadStart('.'))); + assert_eq!(PathBuf::from_param("/test/*tt"), Err(UriSegmentError::BadStart('*'))); + assert_eq!(PathBuf::from_param("/test/tt:"), Err(UriSegmentError::BadEnd(':'))); + assert_eq!(PathBuf::from_param("/test/tt<"), Err(UriSegmentError::BadEnd('<'))); + assert_eq!(PathBuf::from_param("/test/tt>"), Err(UriSegmentError::BadEnd('>'))); + assert_eq!(PathBuf::from_param("/seg1/seg2/"), + Ok(PathBuf::from_iter(vec!["seg1", "seg2"]))); + assert_eq!(PathBuf::from_param("/seg1/../seg2/"), + Ok(PathBuf::from_iter(vec!["seg2"]))); + } #[test] fn test_recognizer() {