diff --git a/encoding/yaml/yaml_test.go b/encoding/yaml/yaml_test.go index ae506bb019c..f71838d78c5 100644 --- a/encoding/yaml/yaml_test.go +++ b/encoding/yaml/yaml_test.go @@ -184,6 +184,7 @@ func TestYAMLValues(t *testing.T) { {`"-.Inf"`, `"-.Inf"`}, {`"2002"`, `"2002"`}, {`"685_230.15"`, `"685_230.15"`}, + {`"0x123456789012345678901234567890"`, `"0x123456789012345678901234567890"`}, // Legacy values.format. {`"no"`, `"no"`}, diff --git a/internal/encoding/yaml/encode.go b/internal/encoding/yaml/encode.go index 55871dab314..87aec6e417a 100644 --- a/internal/encoding/yaml/encode.go +++ b/internal/encoding/yaml/encode.go @@ -164,7 +164,7 @@ func shouldQuote(str string) bool { // This regular expression conservatively matches any date, time string, // or base60 float. -var useQuote = regexp.MustCompile(`^[\-+0-9:\. \t]+([-:]|[tT])[\-+0-9:\. \t]+[zZ]?$`) +var useQuote = regexp.MustCompile(`^[\-+0-9:\. \t]+([-:]|[tT])[\-+0-9:\. \t]+[zZ]?$|^0x[a-fA-F0-9]+$`) // legacyStrings contains a map of fixed strings with special meaning for any // type in the YAML Tag registry (https://yaml.org/type/index.html) as used diff --git a/internal/encoding/yaml/encode_test.go b/internal/encoding/yaml/encode_test.go index a21a21f799f..d26ee4d417c 100644 --- a/internal/encoding/yaml/encode_test.go +++ b/internal/encoding/yaml/encode_test.go @@ -36,6 +36,8 @@ func TestEncodeFile(t *testing.T) { in: ` package test + bighex: "0x1234567890123456789001234567890" + nothex: "0x1234567890123456789001234567890zz" seq: [ 1, 2, 3, { a: 1 @@ -50,6 +52,8 @@ func TestEncodeFile(t *testing.T) { } `, out: ` +bighex: "0x1234567890123456789001234567890" +nothex: 0x1234567890123456789001234567890zz seq: - 1 - 2