tustvold commented on code in PR #3663:
URL: https://github.com/apache/arrow-rs/pull/3663#discussion_r1096714708


##########
object_store/src/path/mod.rs:
##########
@@ -162,6 +162,13 @@ impl Path {
         })
     }
 
+    /// Parse a url encoded string as a [`Path`], returning a [`Error`] if 
invalid,
+    /// as defined on the docstring for [`Path`]
+    pub fn from_url_path(path: impl AsRef<str>) -> Result<Self, Error> {

Review Comment:
   What do you think of this taking `AsRef<Url>`?



##########
object_store/src/path/mod.rs:
##########
@@ -551,6 +558,15 @@ mod tests {
         assert_eq!(b.raw, c.raw);
     }
 
+    #[test]
+    fn from_url_path() {
+        let a = Path::from_url_path("foo%20bar/baz").unwrap();
+        assert_eq!(a.raw, "foo bar/baz");
+
+        let b = Path::from_url_path("bar/baz").unwrap();
+        assert_eq!(b.raw, "bar/baz");

Review Comment:
   Could we get tests of things like
   
   ```
   foo/%2E%2E/bar -> Error
   foo%2F%252E%252E%2Fbar -> foo/%2E%2E/bar
   foo/%252E%252E/bar -> foo/%2E%2E/bar
   %48%45%4C%4C%4F -> HELLO
   foo/%FF/as -> Error
   ```



##########
object_store/src/path/mod.rs:
##########
@@ -162,6 +162,13 @@ impl Path {
         })
     }
 
+    /// Parse a url encoded string as a [`Path`], returning a [`Error`] if 
invalid,
+    /// as defined on the docstring for [`Path`]
+    pub fn from_url_path(path: impl AsRef<str>) -> Result<Self, Error> {
+        let decoded_path = 
percent_encoding::percent_decode_str(path.as_ref()).decode_utf8_lossy();

Review Comment:
   I think it would be better for this to return an error if non-Unicode, e.g.
   
   ```
   percent_encoding::percent_decode_str(path)
     .decode_utf8()
     .context(NonUnicodeSnafu { path })?;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to