plusplusjiajia commented on code in PR #893:
URL: https://github.com/apache/iceberg-cpp/pull/893#discussion_r3855400740


##########
src/iceberg/util/location_util.cc:
##########
@@ -19,14 +19,45 @@
 
 #include "iceberg/util/location_util.h"
 
+#include <algorithm>
+#include <cctype>
+
 namespace iceberg {
 
+namespace {
+
+/// Whether `candidate` is a syntactically valid URI scheme (RFC 3986 section
+/// 3.1): a letter followed by letters, digits, `+`, `-` or `.`.
+bool IsValidScheme(std::string_view candidate) {
+  if (candidate.empty() || !std::isalpha(static_cast<unsigned 
char>(candidate.front()))) {
+    return false;
+  }
+  return std::ranges::all_of(candidate, [](char c) {
+    const auto uc = static_cast<unsigned char>(c);
+    return std::isalnum(uc) || c == '+' || c == '-' || c == '.';
+  });
+}
+
+}  // namespace
+
 std::string_view LocationUtil::ParseScheme(std::string_view location) {
   const auto colon = location.find(':');
   if (colon == std::string_view::npos || colon == 0) {
     return {};
   }
-  return location.substr(0, colon);
+  const auto candidate = location.substr(0, colon);
+  // Cannot be a scheme -> a path whose first segment has a colon, such as the
+  // extended-length Windows form `\\?\C:\...`.
+  if (!IsValidScheme(candidate)) {
+    return {};
+  }
+#ifdef _WIN32
+  // A single letter before the colon is a drive, not a scheme.
+  if (candidate.size() == 1) {

Review Comment:
   @wgtmac Good point on Java parity — I looked into why Java gets away without 
it: drive-letter handling lives below it in Hadoop's `Path`. We have no such 
layer, so without this guard every absolute Windows path fails
     resolution (`No FileIO registered for URI scheme 'c'`, 
https://github.com/apache/iceberg-cpp/actions/runs/32685994120). I've kept it 
for now, but happy to move it elsewhere if you'd prefer `ParseScheme` to stay 
literal.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to