File tree Expand file tree Collapse file tree
test/kotlin/org/pkl/core/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -892,6 +892,9 @@ public static void validateFileUri(URI uri) throws URISyntaxException {
892892 if (!uri .getSchemeSpecificPart ().startsWith ("/" )) {
893893 throw new URISyntaxException (uri .toString (), ErrorMessages .create ("invalidOpaqueFileUri" ));
894894 }
895+ if (uri .getRawAuthority () != null ) {
896+ throw new URISyntaxException (uri .toString (), ErrorMessages .create ("invalidRemoteFileUri" ));
897+ }
895898 }
896899
897900 public static void validateRewriteRule (URI rewrite ) {
Original file line number Diff line number Diff line change @@ -1130,6 +1130,9 @@ invalidOpaqueFileUri=\
11301130File URIs must have a path that starts with `/` (e.g. file:/path/to/my_module.pkl).\n \
11311131To resolve relative paths, remove the scheme prefix (remove "file:").
11321132
1133+ invalidRemoteFileUri =\
1134+ File URIs may not include an authority.
1135+
11331136invalidStringBase64 =\
11341137`{0}` is not in base64 encoding.
11351138
Original file line number Diff line number Diff line change 11/*
2- * Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
2+ * Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -400,6 +400,13 @@ class IoUtilsTest {
400400 assertThrows<IllegalArgumentException > { IoUtils .readString(URI (" http://example.com" ).toURL()) }
401401 }
402402
403+ @Test
404+ fun `toUrl() throws UnsupportedOperationException for file URIs with remote hostnames` () {
405+ val uri = URI (" file://example.com/bar/baz.pkl" )
406+ val exception = assertThrows<URISyntaxException > { IoUtils .validateFileUri(uri) }
407+ assertThat(exception.message).contains(" File URIs may not include an authority." )
408+ }
409+
403410 @Test
404411 fun `encodePath encodes characters reserved on windows` () {
405412 assertThat(IoUtils .encodePath(" foo:bar" )).isEqualTo(" foo(3a)bar" )
You can’t perform that action at this time.
0 commit comments