diff --git a/compiler/protogen/protogen.go b/compiler/protogen/protogen.go index 17cbe1a39..2ee676fbb 100644 --- a/compiler/protogen/protogen.go +++ b/compiler/protogen/protogen.go @@ -251,12 +251,13 @@ func (opts Options) New(req *pluginpb.CodeGeneratorRequest) (*Plugin, error) { "\t• a \"M\" argument on the command line.\n\n"+ "See %v for more information.\n", fdesc.GetName(), goPackageDocURL) - case !strings.Contains(string(importPaths[filename]), "/"): - // Check that import paths contain at least one slash to avoid a - // common mistake where import path is confused with package name. + case !strings.Contains(string(importPaths[filename]), ".") && + !strings.Contains(string(importPaths[filename]), "/"): + // Check that import paths contain at least a dot or slash to avoid + // a common mistake where import path is confused with package name. return nil, fmt.Errorf( "invalid Go import path %q for %q\n\n"+ - "The import path must contain at least one forward slash ('/') character.\n\n"+ + "The import path must contain at least one period ('.') or forward slash ('/') character.\n\n"+ "See %v for more information.\n", string(importPaths[filename]), fdesc.GetName(), goPackageDocURL) case packageNames[filename] == "": diff --git a/compiler/protogen/protogen_test.go b/compiler/protogen/protogen_test.go index 613d6b9a5..4f5ceeda7 100644 --- a/compiler/protogen/protogen_test.go +++ b/compiler/protogen/protogen_test.go @@ -108,6 +108,14 @@ func TestPackageNamesAndPaths(t *testing.T) { wantImportPath: "golang.org/x/foo", wantFilename: "golang.org/x/foo/filename", }, + { + desc: "go_package option sets import path without slashes", + goPackageOption: "golang.org;foo", + generate: true, + wantPackageName: "foo", + wantImportPath: "golang.org", + wantFilename: "golang.org/filename", + }, { desc: "go_package option sets import path and package", goPackageOption: "golang.org/x/foo;bar",