diff options
author | Richard Walters <rwalters@digitalstirling.com> | 2020-10-12 14:31:57 -0700 |
---|---|---|
committer | Richard Walters <rwalters@digitalstirling.com> | 2020-10-12 14:31:57 -0700 |
commit | 1cf1579ebbf20590a8297c62cbf95ffaf095a9ca (patch) | |
tree | 7c95b7d02e98f0acffcafe1c8f111672ebca6dc3 | |
parent | 6a72e51973ec448f3b3d5c9c3f52daeb70829530 (diff) |
Clean up Uri::parse_path and make it functional
-rw-r--r-- | src/lib.rs | 32 |
1 files changed, 15 insertions, 17 deletions
@@ -934,35 +934,33 @@ impl Uri { } fn parse_path(path_string: &str) -> Result<Vec<Vec<u8>>, Error> { - // TODO: improvement: make an iterator and only collect at the end. - let mut path_encoded = Vec::<String>::new(); match path_string { "/" => { - // Special case of a path that is empty but needs a single - // empty-string element to indicate that it is absolute. - path_encoded.push("".to_string()); + // Special case of an empty absolute path, which we want to + // represent as single empty-string element to indicate that it + // is absolute. + Ok(vec![vec![]]) }, "" => { + // Special case of an empty relative path, which we want to + // represent as an empty vector. + Ok(vec![]) }, path_string => { - path_encoded = path_string + path_string .split('/') - .map(String::from) + .map(|segment| { + Self::decode_element( + &segment, + &PCHAR_NOT_PCT_ENCODED, + Context::Path + ) + }) .collect() } } - path_encoded.into_iter().map( - |segment| { - Self::decode_element( - &segment, - &PCHAR_NOT_PCT_ENCODED, - Context::Path - ) - } - ) - .collect::<Result<Vec<Vec<u8>>, Error>>() } fn parse_query(query_and_or_fragment: &str) -> Result<Option<Vec<u8>>, Error> { |