aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Walters <rwalters@digitalstirling.com>2020-10-12 14:31:57 -0700
committerRichard Walters <rwalters@digitalstirling.com>2020-10-12 14:31:57 -0700
commit1cf1579ebbf20590a8297c62cbf95ffaf095a9ca (patch)
tree7c95b7d02e98f0acffcafe1c8f111672ebca6dc3
parent6a72e51973ec448f3b3d5c9c3f52daeb70829530 (diff)
Clean up Uri::parse_path and make it functional
-rw-r--r--src/lib.rs32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f5257b4..45400c6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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> {