mirror of
https://github.com/apple/pkl.git
synced 2026-05-03 05:34:26 +02:00
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:
1
pkl-core/src/test/files/LanguageSnippetTests/input/errors/invalidFileUri1.pkl
vendored
Normal file
1
pkl-core/src/test/files/LanguageSnippetTests/input/errors/invalidFileUri1.pkl
vendored
Normal file
@@ -0,0 +1 @@
|
||||
res = read("file:path/to/foo.txt")
|
||||
1
pkl-core/src/test/files/LanguageSnippetTests/input/errors/invalidFileUri2.pkl
vendored
Normal file
1
pkl-core/src/test/files/LanguageSnippetTests/input/errors/invalidFileUri2.pkl
vendored
Normal file
@@ -0,0 +1 @@
|
||||
res = read*("file:path/to/foo.txt")
|
||||
1
pkl-core/src/test/files/LanguageSnippetTests/input/errors/invalidFileUri3.pkl
vendored
Normal file
1
pkl-core/src/test/files/LanguageSnippetTests/input/errors/invalidFileUri3.pkl
vendored
Normal file
@@ -0,0 +1 @@
|
||||
res = import("file:path/to/foo.pkl")
|
||||
9
pkl-core/src/test/files/LanguageSnippetTests/input/errors/invalidFileUri4.pkl
vendored
Normal file
9
pkl-core/src/test/files/LanguageSnippetTests/input/errors/invalidFileUri4.pkl
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
// Ideally, this should have the same error message as `invalidFileUri2`; the error is that the glob
|
||||
// pattern is invalid.
|
||||
//
|
||||
// But, this is somewhat challenging to fix, because the `URISyntaxException` gets thrown before
|
||||
// `ImportGlobNode` is initialized.
|
||||
//
|
||||
// Regardless, this error is good enough (given this error message, users know what to do), and we
|
||||
// can afford to be pragmatic here.
|
||||
res = import*("file:path/to/foo.pkl")
|
||||
13
pkl-core/src/test/files/LanguageSnippetTests/output/errors/invalidFileUri1.err
vendored
Normal file
13
pkl-core/src/test/files/LanguageSnippetTests/output/errors/invalidFileUri1.err
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
–– Pkl Error ––
|
||||
Resource URI `file:path/to/foo.txt` has invalid syntax.
|
||||
|
||||
x | res = read("file:path/to/foo.txt")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at invalidFileUri1#res (file:///$snippetsDir/input/errors/invalidFileUri1.pkl)
|
||||
|
||||
File URIs must have a path that starts with `/` (e.g. file:/path/to/my_module.pkl).
|
||||
To resolve relative paths, remove the scheme prefix (remove "file:").
|
||||
|
||||
xxx | text = renderer.renderDocument(value)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at pkl.base#Module.output.text (pkl:base)
|
||||
12
pkl-core/src/test/files/LanguageSnippetTests/output/errors/invalidFileUri2.err
vendored
Normal file
12
pkl-core/src/test/files/LanguageSnippetTests/output/errors/invalidFileUri2.err
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
–– Pkl Error ––
|
||||
Invalid glob pattern `file:path/to/foo.txt`.
|
||||
|
||||
x | res = read*("file:path/to/foo.txt")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at invalidFileUri2#res (file:///$snippetsDir/input/errors/invalidFileUri2.pkl)
|
||||
|
||||
Scheme `file` requires a hierarchical path (there must be a `/` after the first colon).
|
||||
|
||||
xxx | text = renderer.renderDocument(value)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at pkl.base#Module.output.text (pkl:base)
|
||||
13
pkl-core/src/test/files/LanguageSnippetTests/output/errors/invalidFileUri3.err
vendored
Normal file
13
pkl-core/src/test/files/LanguageSnippetTests/output/errors/invalidFileUri3.err
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
–– Pkl Error ––
|
||||
Module URI `file:path/to/foo.pkl` has invalid syntax.
|
||||
|
||||
x | res = import("file:path/to/foo.pkl")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at invalidFileUri3#res (file:///$snippetsDir/input/errors/invalidFileUri3.pkl)
|
||||
|
||||
File URIs must have a path that starts with `/` (e.g. file:/path/to/my_module.pkl).
|
||||
To resolve relative paths, remove the scheme prefix (remove "file:").
|
||||
|
||||
xxx | text = renderer.renderDocument(value)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at pkl.base#Module.output.text (pkl:base)
|
||||
13
pkl-core/src/test/files/LanguageSnippetTests/output/errors/invalidFileUri4.err
vendored
Normal file
13
pkl-core/src/test/files/LanguageSnippetTests/output/errors/invalidFileUri4.err
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
–– Pkl Error ––
|
||||
Module URI `file:path/to/foo.pkl` has invalid syntax.
|
||||
|
||||
x | res = import*("file:path/to/foo.pkl")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at invalidFileUri4#res (file:///$snippetsDir/input/errors/invalidFileUri4.pkl)
|
||||
|
||||
File URIs must have a path that starts with `/` (e.g. file:/path/to/my_module.pkl).
|
||||
To resolve relative paths, remove the scheme prefix (remove "file:").
|
||||
|
||||
xxx | text = renderer.renderDocument(value)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
at pkl.base#Module.output.text (pkl:base)
|
||||
Reference in New Issue
Block a user