-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* encode: fix localdate formatting * encode: fix empty key marshaling * encode: fix invalid quotation of time.Time * encode: ensure control chars are escaped * decode: always use UTC for zero tz * encode: check for invalid characters in keys * encode: always construct map for empty array tables * fuzz: add go 1.18 fuzz test * encode: handle NaNs * encode: allow new lines in quoted keys * encode: never emit table inside array * encode: don't capitalize inf
- Loading branch information
Showing
19 changed files
with
230 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
* text=auto | ||
|
||
benchmark/benchmark.toml text eol=lf | ||
testdata/** text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
package toml_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/pelletier/go-toml/v2" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func FuzzUnmarshal(f *testing.F) { | ||
file, err := ioutil.ReadFile("benchmark/benchmark.toml") | ||
if err != nil { | ||
panic(err) | ||
} | ||
f.Add(file) | ||
|
||
f.Fuzz(func(t *testing.T, b []byte) { | ||
if strings.Contains(string(b), "nan") { | ||
// Current limitation of testify. | ||
// https://github.com/stretchr/testify/issues/624 | ||
t.Skip("can't compare NaNs") | ||
} | ||
|
||
t.Log("INITIAL DOCUMENT ===========================") | ||
t.Log(string(b)) | ||
|
||
var v interface{} | ||
err := toml.Unmarshal(b, &v) | ||
if err != nil { | ||
return | ||
} | ||
|
||
t.Log("DECODED VALUE ===========================") | ||
t.Logf("%#+v", v) | ||
|
||
encoded, err := toml.Marshal(v) | ||
if err != nil { | ||
t.Fatalf("cannot marshal unmarshaled document: %s", err) | ||
} | ||
|
||
t.Log("ENCODED DOCUMENT ===========================") | ||
t.Log(string(encoded)) | ||
|
||
var v2 interface{} | ||
err = toml.Unmarshal(encoded, &v2) | ||
if err != nil { | ||
t.Fatalf("failed round trip: %s", err) | ||
} | ||
require.Equal(t, v, v2) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.