mirror of
https://github.com/actix/actix-web.git
synced 2024-11-26 19:41:12 +00:00
tests for PathBuf::from_param
This commit is contained in:
parent
d8f27e95a6
commit
ebfd3ac275
1 changed files with 16 additions and 2 deletions
|
@ -129,8 +129,8 @@ impl FromParam for PathBuf {
|
||||||
return Err(UriSegmentError::BadEnd('>'))
|
return Err(UriSegmentError::BadEnd('>'))
|
||||||
} else if segment.ends_with('<') {
|
} else if segment.ends_with('<') {
|
||||||
return Err(UriSegmentError::BadEnd('<'))
|
return Err(UriSegmentError::BadEnd('<'))
|
||||||
} else if segment.contains('/') {
|
} else if segment.is_empty() {
|
||||||
return Err(UriSegmentError::BadChar('/'))
|
continue
|
||||||
} else if cfg!(windows) && segment.contains('\\') {
|
} else if cfg!(windows) && segment.contains('\\') {
|
||||||
return Err(UriSegmentError::BadChar('\\'))
|
return Err(UriSegmentError::BadChar('\\'))
|
||||||
} else {
|
} else {
|
||||||
|
@ -347,6 +347,20 @@ fn parse(pattern: &str) -> String {
|
||||||
mod tests {
|
mod tests {
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use super::*;
|
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]
|
#[test]
|
||||||
fn test_recognizer() {
|
fn test_recognizer() {
|
||||||
|
|
Loading…
Reference in a new issue