Skip to content

Commit

Permalink
cue/interpreter/embed: require type if glob extension not specified
Browse files Browse the repository at this point in the history
Per the design in https://cuelang.org/discussion/3264, we require the
type argument to be specified if the extension provided in a glob
pattern is not fully specified.

The current implementation does not implement that behaviour. This CL
corrects that.

Fixes #3274.

Signed-off-by: Paul Jolly <[email protected]>
Change-Id: If07d966fd51fce0634bd4da38853cf974ad2d202
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1197339
TryBot-Result: CUEcueckoo <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Roger Peppe <[email protected]>
Reviewed-by: Marcel van Lohuizen <[email protected]>
  • Loading branch information
myitcv committed Jul 8, 2024
1 parent 970d10f commit 2c8ee2f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/cue/cmd/testdata/script/embed_err.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ noTranslateBS: _ @embed(file="x\\test.json")
autoCUEfiletype: _ @embed(file="x.cue")
explicitCUEfiletype: _ @embed(file=xcue, type=cue)

// intentional missing type arg
unspecifiedFiletype1: _ @embed(glob=x/*.*)
unspecifiedFiletype2: _ @embed(glob=x/*)
unspecifiedFiletype3: _ @embed(glob=x/*.?son)
unspecifiedFiletype4: _ @embed(glob=x/*.[j]son)

-- test.json --
{ "x": 34 }
-- test.ldjson --
Expand Down Expand Up @@ -116,3 +122,11 @@ x: 5
./test.cue:43:20
@embed: encoding "cue" not (yet) supported:
./test.cue:44:24
@embed: extension not fully specified; type argument required:
./test.cue:47:25
@embed: extension not fully specified; type argument required:
./test.cue:48:25
@embed: extension not fully specified; type argument required:
./test.cue:49:25
@embed: extension not fully specified; type argument required:
./test.cue:50:25
10 changes: 10 additions & 0 deletions cue/interpreter/embed/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ func (c *compiler) processGlob(glob, scope string, schema adt.Value) (adt.Expr,
return nil, errors.Newf(c.pos, "double star not (yet) supported in glob")
}

// If we do not have a type, ensure the extension of the base is fully
// specified, i.e. does not contain any meta characters as specified by
// path.Match.
if scope == "" {
ext := path.Ext(path.Base(glob))
if ext == "" || strings.ContainsAny(ext, "*?[\\") {
return nil, errors.Newf(c.pos, "extension not fully specified; type argument required")
}
}

m := &adt.StructLit{}

matches, err := fs.Glob(c.fs, glob)
Expand Down

0 comments on commit 2c8ee2f

Please sign in to comment.