From c3470ca83cfdbcc71ce162b00d6b9a0004a7f649 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Mon, 25 Apr 2022 15:40:00 +0930 Subject: [PATCH] internal/fuzz: trim carriage return from version line On windows hosts, when code is checked out using git with the default setting of autocrlf=true, carriage returns are appended to source lines which then prevent the version check from being successful. This removes carriage returns to allow version matching. Fixes #52268 Change-Id: I9acc4e907c93a20305f8742cc01687a122a88645 Reviewed-on: https://go-review.googlesource.com/c/go/+/402074 Reviewed-by: Roland Shoemaker TryBot-Result: Gopher Robot Run-TryBot: Dan Kortschak Reviewed-by: Ian Lance Taylor --- src/internal/fuzz/encoding.go | 6 ++++-- src/internal/fuzz/encoding_test.go | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/internal/fuzz/encoding.go b/src/internal/fuzz/encoding.go index c95d9e088b..c2eed7045e 100644 --- a/src/internal/fuzz/encoding.go +++ b/src/internal/fuzz/encoding.go @@ -12,6 +12,7 @@ import ( "go/token" "math" "strconv" + "strings" "unicode/utf8" ) @@ -106,8 +107,9 @@ func unmarshalCorpusFile(b []byte) ([]any, error) { if len(lines) < 2 { return nil, fmt.Errorf("must include version and at least one value") } - if string(lines[0]) != encVersion1 { - return nil, fmt.Errorf("unknown encoding version: %s", lines[0]) + version := strings.TrimSuffix(string(lines[0]), "\r") + if version != encVersion1 { + return nil, fmt.Errorf("unknown encoding version: %s", version) } var vals []any for _, line := range lines[1:] { diff --git a/src/internal/fuzz/encoding_test.go b/src/internal/fuzz/encoding_test.go index 8e3800eb77..6f6173d7e0 100644 --- a/src/internal/fuzz/encoding_test.go +++ b/src/internal/fuzz/encoding_test.go @@ -214,6 +214,11 @@ uint(18446744073709551615)` } }(), }, + { + desc: "windows new line", + in: "go test fuzz v1\r\nint(0)\r\n", + want: "go test fuzz v1\nint(0)", + }, } for _, test := range tests { t.Run(test.desc, func(t *testing.T) { -- 2.50.0