Treat opaque file URIs as errors (#1087)

Opaque file URIs are URIs whose scheme-specific part does not start with `/`.
For example, `file:foo/bar.txt` is an opaque URI.

Currently, this has the unintentional behavior of: look for file `foo/bar.txt` from the process working directory.
These are effectively dynamics imports; from a single import, we can't statically analyze what it resolves as.

According to RFC-8089, File URIs must have paths that start with `/`. So, these are actually _not valid URIs_.
See the grammar defined in https://datatracker.ietf.org/doc/html/rfc8089#section-2

This changes Pkl's behavior so that these URIs are treated as errors.
This commit is contained in:
Daniel Chao
2025-06-03 14:57:22 -07:00
committed by GitHub
parent 4eeb61dc74
commit 2bc9c2f424
16 changed files with 109 additions and 9 deletions

View File

@@ -661,6 +661,9 @@ Invalid escape character `\\{0}`.
invalidGlobTooComplex=\
The glob pattern is too complex.
invalidGlobNonHierarchicalUri=\
Scheme `{0}` requires a hierarchical path (there must be a `/` after the first colon).
# used as {1} in invalidModuleUri and invalidResourceUri
invalidTripleDotSyntax=\
expected `...` or `.../path/to/my_module.pkl`
@@ -1057,3 +1060,7 @@ External {0} reader does not support scheme `{1}`.
externalReaderAlreadyTerminated=\
External reader process has already terminated.
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:").