]> Cypherpunks repositories - gostls13.git/commitdiff
internal/fuzz: trim carriage return from version line
authorDan Kortschak <dan@kortschak.io>
Mon, 25 Apr 2022 06:10:00 +0000 (15:40 +0930)
committerDan Kortschak <dan@kortschak.io>
Fri, 20 May 2022 23:05:38 +0000 (23:05 +0000)
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 <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Dan Kortschak <dan@kortschak.io>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/internal/fuzz/encoding.go
src/internal/fuzz/encoding_test.go

index c95d9e088bb2fb832d7872fbbc457c3b9d24ec33..c2eed7045e7b392cd18298b4c410da76ffb4fdf5 100644 (file)
@@ -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:] {
index 8e3800eb77f3ff205cc0ac67d6a6b6c04ccfc7ef..6f6173d7e0122c6e1552d7e8e7f1b36c4c6112d9 100644 (file)
@@ -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) {