Skip to content

Commit 4f3f28a

Browse files
bioballHT154
authored andcommitted
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.
1 parent 99ba9be commit 4f3f28a

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

pkl-core/src/main/java/org/pkl/core/util/IoUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
public final class IoUtils {
4949

5050
// Don't match paths like `C:\`, which are drive letters on Windows.
51-
private static final Pattern uriLike = Pattern.compile("\\w+:[^\\\\].*");
51+
private static final Pattern uriLike = Pattern.compile("[\\w+.-]+:[^\\\\].*");
5252

5353
private static final Pattern windowsPathLike = Pattern.compile("\\w:\\\\.*");
5454

pkl-core/src/test/files/LanguageSnippetTests/input/api/Resource.pkl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,10 @@ examples {
5252

5353
new Resource { base64 = "AQIDBA==" }.bytes
5454
}
55+
56+
// test parsing of URIs.
57+
// see https://github.com/apple/pkl/pull/1335
58+
["absolute URI scheme with plus"] {
59+
module.catch(() -> read("foo+bar///?baz=buz"))
60+
}
5561
}

pkl-core/src/test/files/LanguageSnippetTests/output/api/Resource.pcf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ examples {
3636
"AQIDBA=="
3737
Bytes(1, 2, 3, 4)
3838
}
39+
["absolute URI scheme with plus"] {
40+
"Cannot find resource `foo+bar///?baz=buz`."
41+
}
3942
}

0 commit comments

Comments
 (0)