cmd/go/internal/vgo: accept \r\n line ending after import comment

Gofmt removes \r\n line endings, but sometimes Windows tools
convert the Go source code and it takes a while before gofmt gets
a chance to convert it back.

Fixes golang/go#23952.

Change-Id: I24d205a519d2527568fb39b811d1d3b33aca138a
Reviewed-on: https://go-review.googlesource.com/107662
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
diff --git a/vendor/cmd/go/internal/vgo/init.go b/vendor/cmd/go/internal/vgo/init.go
index b6e2e7c..09704ac 100644
--- a/vendor/cmd/go/internal/vgo/init.go
+++ b/vendor/cmd/go/internal/vgo/init.go
@@ -292,8 +292,8 @@
 }
 
 var (
-	gitOriginRE     = regexp.MustCompile(`(?m)^\[remote "origin"\]\n\turl = (?:https://github.com/|git@github.com:|gh:)([^/]+/[^/]+?)(\.git)?\n`)
-	importCommentRE = regexp.MustCompile(`(?m)^package[ \t]+[^ \t\n/]+[ \t]+//[ \t]+import[ \t]+(\"[^"]+\")[ \t]*\n`)
+	gitOriginRE     = regexp.MustCompile(`(?m)^\[remote "origin"\]\r?\n\turl = (?:https://github.com/|git@github.com:|gh:)([^/]+/[^/]+?)(\.git)?\r?\n`)
+	importCommentRE = regexp.MustCompile(`(?m)^package[ \t]+[^ \t\r\n/]+[ \t]+//[ \t]+import[ \t]+(\"[^"]+\")[ \t]*\r?\n`)
 )
 
 func findImportComment(file string) string {
diff --git a/vendor/cmd/go/vgo_test.go b/vendor/cmd/go/vgo_test.go
index 082c1d7..ed00e37 100644
--- a/vendor/cmd/go/vgo_test.go
+++ b/vendor/cmd/go/vgo_test.go
@@ -25,7 +25,7 @@
 	tg.run("env")
 }
 
-func TestFindModRoot(t *testing.T) {
+func TestFindModuleRoot(t *testing.T) {
 	tg := testgo(t)
 	defer tg.cleanup()
 	tg.makeTempdir()
@@ -52,6 +52,32 @@
 	}
 }
 
+func TestFindModulePath(t *testing.T) {
+	tg := testgo(t)
+	defer tg.cleanup()
+	tg.makeTempdir()
+
+	tg.must(os.MkdirAll(tg.path("x"), 0777))
+	tg.must(ioutil.WriteFile(tg.path("x/x.go"), []byte("package x // import \"x\"\n"), 0666))
+	path, err := vgo.FindModulePath(tg.path("x"))
+	if err != nil {
+		t.Fatal(err)
+	}
+	if path != "x" {
+		t.Fatalf("FindModulePath = %q, want %q", path, "x")
+	}
+
+	// Windows line-ending.
+	tg.must(ioutil.WriteFile(tg.path("x/x.go"), []byte("package x // import \"x\"\r\n"), 0666))
+	path, err = vgo.FindModulePath(tg.path("x"))
+	if err != nil {
+		t.Fatal(err)
+	}
+	if path != "x" {
+		t.Fatalf("FindModulePath = %q, want %q", path, "x")
+	}
+}
+
 func TestLocalModule(t *testing.T) {
 	// Test that local replacements work
 	// and that they can use a dummy name