diff options
| author | Udalov Max <re.udalov@gmail.com> | 2019-04-23 12:53:35 +0300 |
|---|---|---|
| committer | Jay Conrod <jayconrod@google.com> | 2019-04-24 00:09:18 +0000 |
| commit | de050717f1b668dfd196f1dc4d18c77d03f3afb4 (patch) | |
| tree | 5d5929e298124e4e91b3915c7045f827f96f4762 /src | |
| parent | 601eee39de1f9d215274f54d57af80ee163e11f1 (diff) | |
| download | go-de050717f1b668dfd196f1dc4d18c77d03f3afb4.tar.xz | |
cmd/go/internal/modcmd: assign module's path and version to fileJSON when modFile's module statement exists
Fixes panic on nil pointer dereference error when assigning module's path and version pair to fileJSON.
Fixes #31623
Change-Id: I3f61122ba0676a1270d3ad98900af8c8e9c90935
Reviewed-on: https://go-review.googlesource.com/c/go/+/173397
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/go/internal/modcmd/edit.go | 4 | ||||
| -rw-r--r-- | src/cmd/go/testdata/script/mod_edit.txt | 16 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/cmd/go/internal/modcmd/edit.go b/src/cmd/go/internal/modcmd/edit.go index 5066e4ddf7..1be8b7cb2f 100644 --- a/src/cmd/go/internal/modcmd/edit.go +++ b/src/cmd/go/internal/modcmd/edit.go @@ -385,7 +385,9 @@ type replaceJSON struct { // editPrintJSON prints the -json output. func editPrintJSON(modFile *modfile.File) { var f fileJSON - f.Module = modFile.Module.Mod + if modFile.Module != nil { + f.Module = modFile.Module.Mod + } if modFile.Go != nil { f.Go = modFile.Go.Version } diff --git a/src/cmd/go/testdata/script/mod_edit.txt b/src/cmd/go/testdata/script/mod_edit.txt index aa714e8b3c..42007b13d0 100644 --- a/src/cmd/go/testdata/script/mod_edit.txt +++ b/src/cmd/go/testdata/script/mod_edit.txt @@ -25,6 +25,10 @@ cmpenv go.mod $WORK/go.mod.edit2 go mod edit -json cmpenv stdout $WORK/go.mod.json +# go mod edit -json (empty mod file) +go mod edit -json $WORK/go.mod.empty +cmp stdout $WORK/go.mod.empty.json + # go mod edit -replace go mod edit -replace=x.1@v1.3.0=y.1/v2@v2.3.5 -replace=x.1@v1.4.0=y.1/v2@v2.3.5 cmpenv go.mod $WORK/go.mod.edit3 @@ -168,4 +172,14 @@ require x.3 v1.99.0 -- $WORK/m/go.mod.edit -- module x.x/y/z -go $goversion
\ No newline at end of file +go $goversion +-- $WORK/go.mod.empty -- +-- $WORK/go.mod.empty.json -- +{ + "Module": { + "Path": "" + }, + "Require": null, + "Exclude": null, + "Replace": null +} |
