diff --git a/mod/modfile/modfile.go b/mod/modfile/modfile.go index 7b04ca226..9b28805f1 100644 --- a/mod/modfile/modfile.go +++ b/mod/modfile/modfile.go @@ -207,9 +207,13 @@ func parse(modfile []byte, filename string, strict bool) (*File, error) { mf.Module += "@v0" } if mf.Language != nil { - if vers := mf.Language.Version; vers != "" && !semver.IsValid(vers) { + vers := mf.Language.Version + if !semver.IsValid(vers) { return nil, fmt.Errorf("language version %q in %s is not well formed", vers, filename) } + if semver.Canonical(vers) != vers { + return nil, fmt.Errorf("language version %v in %s is not canonical", vers, filename) + } } var versions []module.Version // The main module is always the default for its own major version. diff --git a/mod/modfile/modfile_test.go b/mod/modfile/modfile_test.go index 89406e9bf..fe33102ce 100644 --- a/mod/modfile/modfile_test.go +++ b/mod/modfile/modfile_test.go @@ -122,6 +122,21 @@ module: "foo.com/bar@v0" language: version: "vblah" module: "foo.com/bar@v0"`, wantError: `language version "vblah" in module.cue is not well formed`, +}, { + testName: "EmptyLanguageVersion", + parse: Parse, + data: ` +language: {} +module: "foo.com/bar@v0"`, + wantError: `language version "" in module.cue is not well formed`, +}, { + testName: "NonCanonicalLanguageVersion", + parse: Parse, + data: ` +module: "foo.com/bar@v0" +language: version: "v0.8" +`, + wantError: `language version v0.8 in module.cue is not canonical`, }, { testName: "InvalidDepVersion", parse: Parse,