compiler/protogen: relax rules for valid import paths

The path "sub.example.com" is a valid Go import path and
should not be rejected. Relax the check to require at least one
dot or slash. Either way, it still prevents the situation where
a user erroneously treats this option as just the package name.

Change-Id: I3df811e1eae61c9d2a0b81c001a27cc7c08c3838
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/316949
Trust: Joe Tsai <joetsai@digital-static.net>
Trust: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Damien Neil <dneil@google.com>
diff --git a/compiler/protogen/protogen.go b/compiler/protogen/protogen.go
index 17cbe1a..2ee676f 100644
--- a/compiler/protogen/protogen.go
+++ b/compiler/protogen/protogen.go
@@ -251,12 +251,13 @@
 					"\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 613d6b9..4f5ceed 100644
--- a/compiler/protogen/protogen_test.go
+++ b/compiler/protogen/protogen_test.go
@@ -109,6 +109,14 @@
 			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",
 			generate:        true,