-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cue/interpreter/embed: forbid
**
via pkg/path.Match
Our pkg/path.Match func mimics Go's own path.Match in that it can be used as a validator via `Match(pattern, "")`. This is better than a `strings.Contains(pattern, "**")` not only because we get consistent error messages, but also because Contains gives false positives on valid patterns such as `\**`, which escapes the first star, or `[x**y]`, where the stars are just part of a character set. Fix the code, and add more tests that demonstrate that embedding does support a glob with `\**` now. This brings embed in line with pkg/path.Match and tool/file.Glob in terms of what pattern matching syntax and features it supports. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I0ed6fcab9426c6392fb18491a3f656f29c56b41e Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1198692 Reviewed-by: Roger Peppe <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
- Loading branch information
Showing
3 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
env CUE_EXPERIMENT=embed | ||
|
||
[!windows] cp reuse.json 'star/*.json' | ||
[!windows] exec cue export --out cue | ||
[!windows] cmp stdout out/export-unix | ||
|
||
[windows] exec cue export --out cue | ||
[windows] cmp stdout out/export-windows | ||
|
||
-- test.cue -- | ||
@extern(embed) | ||
|
||
package foo | ||
|
||
// Unix OSes can have a file containing a star character, and we can match it. | ||
// Windows can still use these file paths and glob patterns, but they can't match | ||
// a file containing a star character, as such filenames are not allowed on Windows. | ||
|
||
globStar: _ @embed(glob="star/*.json") | ||
globEscapeStar: _ @embed(glob="star/\\**", type=json) | ||
-- reuse.json -- | ||
{"x": "to be reused for more names"} | ||
-- star/simple.json -- | ||
{"x": "does not contain a star character"} | ||
-- out/export-unix -- | ||
globStar: { | ||
"star/*.json": x: "to be reused for more names" | ||
"star/simple.json": x: "does not contain a star character" | ||
} | ||
globEscapeStar: "star/*.json": x: "to be reused for more names" | ||
-- out/export-windows -- | ||
globStar: "star/simple.json": x: "does not contain a star character" | ||
globEscapeStar: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters