this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue/interpreter/embed: require type if glob extension not specified

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 <paul@myitcv.io>
Change-Id: If07d966fd51fce0634bd4da38853cf974ad2d202
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1197339
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>

+24
+14
cmd/cue/cmd/testdata/script/embed_err.txtar
··· 50 50 autoCUEfiletype: _ @embed(file="x.cue") 51 51 explicitCUEfiletype: _ @embed(file=xcue, type=cue) 52 52 53 + // intentional missing type arg 54 + unspecifiedFiletype1: _ @embed(glob=x/*.*) 55 + unspecifiedFiletype2: _ @embed(glob=x/*) 56 + unspecifiedFiletype3: _ @embed(glob=x/*.?son) 57 + unspecifiedFiletype4: _ @embed(glob=x/*.[j]son) 58 + 53 59 -- test.json -- 54 60 { "x": 34 } 55 61 -- test.ldjson -- ··· 116 122 ./test.cue:43:20 117 123 @embed: encoding "cue" not (yet) supported: 118 124 ./test.cue:44:24 125 + @embed: extension not fully specified; type argument required: 126 + ./test.cue:47:25 127 + @embed: extension not fully specified; type argument required: 128 + ./test.cue:48:25 129 + @embed: extension not fully specified; type argument required: 130 + ./test.cue:49:25 131 + @embed: extension not fully specified; type argument required: 132 + ./test.cue:50:25
+10
cue/interpreter/embed/embed.go
··· 216 216 return nil, errors.Newf(c.pos, "double star not (yet) supported in glob") 217 217 } 218 218 219 + // If we do not have a type, ensure the extension of the base is fully 220 + // specified, i.e. does not contain any meta characters as specified by 221 + // path.Match. 222 + if scope == "" { 223 + ext := path.Ext(path.Base(glob)) 224 + if ext == "" || strings.ContainsAny(ext, "*?[\\") { 225 + return nil, errors.Newf(c.pos, "extension not fully specified; type argument required") 226 + } 227 + } 228 + 219 229 m := &adt.StructLit{} 220 230 221 231 matches, err := fs.Glob(c.fs, glob)