[fix] Add support for handling remote file URIs. (#629)

Co-authored-by: Jen Basch <jbasch@apple.com>
This commit is contained in:
Carpe-WangandJen Basch authored and GitHub committed 2026-10-15 14:05:46 -07:00
1 parent 8399f11186
commit eff9a9e164
3 files changed
+14 -1

No files matched your search

@@ -892,6 +892,9 @@ public final class IoUtils {
if (!uri.getSchemeSpecificPart().startsWith("/")) {
throw new URISyntaxException(uri.toString(), ErrorMessages.create("invalidOpaqueFileUri"));
}
if (uri.getRawAuthority() != null) {
throw new URISyntaxException(uri.toString(), ErrorMessages.create("invalidRemoteFileUri"));
}
}
public static void validateRewriteRule(URI rewrite) {
@@ -1130,6 +1130,9 @@ invalidOpaqueFileUri=\
File URIs must have a path that starts with `/` (e.g. file:/path/to/my_module.pkl).\n\
To resolve relative paths, remove the scheme prefix (remove "file:").
invalidRemoteFileUri=\
File URIs may not include an authority.
invalidStringBase64=\
`{0}` is not in base64 encoding.
@@ -1,5 +1,5 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -400,6 +400,13 @@ class IoUtilsTest {
assertThrows<IllegalArgumentException> { IoUtils.readString(URI("http://example.com").toURL()) }
}
@Test
fun `toUrl() throws UnsupportedOperationException for file URIs with remote hostnames`() {
val uri = URI("file://example.com/bar/baz.pkl")
val exception = assertThrows<URISyntaxException> { IoUtils.validateFileUri(uri) }
assertThat(exception.message).contains("File URIs may not include an authority.")
}
@Test
fun `encodePath encodes characters reserved on windows`() {
assertThat(IoUtils.encodePath("foo:bar")).isEqualTo("foo(3a)bar")