zabetak commented on code in PR #5334:
URL: https://github.com/apache/calcite/pull/5334#discussion_r4389783276
##########
file/src/main/java/org/apache/calcite/adapter/file/FileSchema.java:
##########
@@ -119,10 +130,60 @@ private static String trim(String s, String suffix) {
return builder.build();
}
+ /** Checks that a model-supplied table URL may be dereferenced by this
+ * adapter: a local {@code file} URL always, a remote one (any other
+ * protocol, or a {@code file} URL naming a host, such as a Windows UNC path)
+ * only when it matches the regular expression
+ * {@link CalciteSystemProperty#FILE_URLS_ALLOWED}. */
+ static void checkUrlAllowed(String url) {
+ checkUrlAllowed(url, CalciteSystemProperty.FILE_URLS_ALLOWED.value());
+ }
+
+ static void checkUrlAllowed(String url, String allowedUrls) {
+ final URI uri;
+ try {
+ uri = new URI(url);
+ uri.toURL();
+ } catch (URISyntaxException | MalformedURLException |
IllegalArgumentException e) {
+ // Malformed; Sources.url parses the same way and will report the error
+ return;
+ }
+ // A "file" URL is local unless it names a host, as an authority
+ // ("file://host/share") or, as Windows resolves it to a UNC path, as a
+ // path starting with two slashes or backslashes ("file:////host/share",
+ // "file:%5C%5Chost%5Cshare")
+ final String path =
+ Util.first(uri.isOpaque() ? uri.getSchemeSpecificPart() :
uri.getPath(), "");
+ if ("file".equalsIgnoreCase(uri.getScheme())
+ && Util.isNullOrEmpty(uri.getRawAuthority())
+ && !path.replace('\\', '/').startsWith("//")) {
+ return;
+ }
Review Comment:
I am not sure if there is well defined notion of a "local" file/URL but we
can go with this solution and refine later if necessary.
--
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]