You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/12/15 21:13:55 UTC

[GitHub] [arrow] westonpace commented on a diff in pull request #14974: ARROW-18436: [C++] Ensure correct (un)escaping of special characters in URI paths

westonpace commented on code in PR #14974:
URL: https://github.com/apache/arrow/pull/14974#discussion_r1050139903


##########
cpp/src/arrow/util/uri.cc:
##########
@@ -306,14 +311,29 @@ Status Uri::Parse(const std::string& uri_string) {
   return Status::OK();
 }
 
-std::string UriFromAbsolutePath(const std::string& path) {
+Result<std::string> UriFromAbsolutePath(const std::string_view& path) {
+  if (path.empty()) {
+    return Status::Invalid(
+        "UriFromAbsolutePath expected an absolute path, got an empty string");
+  }
+  std::string out;
 #ifdef _WIN32
-  // Path is supposed to start with "X:/..."
-  return "file:///" + path;
+  // Turn "/" separators into "\", as Windows recognizes both but uriparser
+  // only the latter.
+  std::string fixed_path(path);
+  std::replace(fixed_path.begin(), fixed_path.end(), '/', '\\');
+  out.resize(8 + 3 * fixed_path.length() + 1);

Review Comment:
   Minor nit: Maybe a comment explaining this math?  Probably not needed if this is a normal Windows thing.



##########
cpp/src/arrow/util/uri.cc:
##########
@@ -58,10 +59,10 @@ bool IsDriveSpec(const std::string_view s) {
 
 }  // namespace
 
-std::string UriEscape(const std::string& s) {
+std::string UriEscape(const std::string_view& s) {

Review Comment:
   Minor nit: I think we've been preferring to pass `string_view` by value in Substrait per https://quuxplusone.github.io/blog/2021/11/09/pass-string-view-by-value/ and @bkietz 's advice



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org