From eff9a9e164619f5c3c85122b52bcd15433dea307 Mon Sep 17 00:00:00 2001 From: Carpe-Wang <78642589+Carpe-Wang@users.noreply.github.com> Date: Fri, 16 Oct 2026 05:05:46 +0800 Subject: [PATCH] [fix] Add support for handling remote file URIs. (#629) Co-authored-by: Jen Basch --- pkl-core/src/main/java/org/pkl/core/util/IoUtils.java | 3 +++ .../main/resources/org/pkl/core/errorMessages.properties | 3 +++ .../src/test/kotlin/org/pkl/core/util/IoUtilsTest.kt | 9 ++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkl-core/src/main/java/org/pkl/core/util/IoUtils.java b/pkl-core/src/main/java/org/pkl/core/util/IoUtils.java index 1a7d16c2c..ba67261b5 100644 --- a/pkl-core/src/main/java/org/pkl/core/util/IoUtils.java +++ b/pkl-core/src/main/java/org/pkl/core/util/IoUtils.java @@ -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) { diff --git a/pkl-core/src/main/resources/org/pkl/core/errorMessages.properties b/pkl-core/src/main/resources/org/pkl/core/errorMessages.properties index c18a2868c..77db29f25 100644 --- a/pkl-core/src/main/resources/org/pkl/core/errorMessages.properties +++ b/pkl-core/src/main/resources/org/pkl/core/errorMessages.properties @@ -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. diff --git a/pkl-core/src/test/kotlin/org/pkl/core/util/IoUtilsTest.kt b/pkl-core/src/test/kotlin/org/pkl/core/util/IoUtilsTest.kt index 8a7076c71..a4c83a023 100644 --- a/pkl-core/src/test/kotlin/org/pkl/core/util/IoUtilsTest.kt +++ b/pkl-core/src/test/kotlin/org/pkl/core/util/IoUtilsTest.kt @@ -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 { 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 { 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")