Fix parsing of URLs with plus signs (#1335)

This fixes an issue where URLs with schemes that contain `+`, `-`, and
`.` would not be parsed correctly.

For example, `foo+bar:///?baz.pkl` would turn into
`foo+bar:///%3Fbaz.pkl`. The query param is lost, and turned into the
path.
This commit is contained in:
Daniel Chao
2025-12-03 10:11:23 -08:00
committed by GitHub
parent d1c652f736
commit 53f3be64f3
3 changed files with 10 additions and 1 deletions

View File

@@ -48,7 +48,7 @@ import org.pkl.core.runtime.VmExceptionBuilder;
public final class IoUtils { public final class IoUtils {
// Don't match paths like `C:\`, which are drive letters on Windows. // Don't match paths like `C:\`, which are drive letters on Windows.
private static final Pattern uriLike = Pattern.compile("\\w+:[^\\\\].*"); private static final Pattern uriLike = Pattern.compile("[\\w+.-]+:[^\\\\].*");
private static final Pattern windowsPathLike = Pattern.compile("\\w:\\\\.*"); private static final Pattern windowsPathLike = Pattern.compile("\\w:\\\\.*");

View File

@@ -52,4 +52,10 @@ examples {
new Resource { base64 = "AQIDBA==" }.bytes new Resource { base64 = "AQIDBA==" }.bytes
} }
// test parsing of URIs.
// see https://github.com/apple/pkl/pull/1335
["absolute URI scheme with plus"] {
module.catch(() -> read("foo+bar///?baz=buz"))
}
} }

View File

@@ -36,4 +36,7 @@ examples {
"AQIDBA==" "AQIDBA=="
Bytes(1, 2, 3, 4) Bytes(1, 2, 3, 4)
} }
["absolute URI scheme with plus"] {
"Cannot find resource `foo+bar///?baz=buz`."
}
} }