Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85e5cf0bf2 |
@@ -10,6 +10,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
@@ -592,7 +593,10 @@ func yamlPathSet(root *yaml.Node, keys []string, value string) error {
|
|||||||
// unquoted 00112233 into the number 38043 and 1e5 into 100000. Tagging
|
// unquoted 00112233 into the number 38043 and 1e5 into 100000. Tagging
|
||||||
// a string setting as a string makes the encoder quote such a value.
|
// a string setting as a string makes the encoder quote such a value.
|
||||||
// Other settings stay unquoted, so compression_level 9 is a number.
|
// Other settings stay unquoted, so compression_level 9 is a number.
|
||||||
if configKeyIsString(keys) {
|
// The encoder refuses to write a value that is not valid UTF-8 as a
|
||||||
|
// string. Left untagged, such a value is written as base64 !!binary and
|
||||||
|
// loads back unchanged.
|
||||||
|
if configKeyIsString(keys) && utf8.ValidString(value) {
|
||||||
node.Tag = yamlStringTag
|
node.Tag = yamlStringTag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,8 @@ func TestConfigSetStringLooksLikeNumber(t *testing.T) {
|
|||||||
func(cfg *config.Config) string { return cfg.S3.Prefix }},
|
func(cfg *config.Config) string { return cfg.S3.Prefix }},
|
||||||
{"s3.bucket", "true",
|
{"s3.bucket", "true",
|
||||||
func(cfg *config.Config) string { return cfg.S3.Bucket }},
|
func(cfg *config.Config) string { return cfg.S3.Bucket }},
|
||||||
|
{"s3.region", "FALSE",
|
||||||
|
func(cfg *config.Config) string { return cfg.S3.Region }},
|
||||||
{"snapshots.home.exclude.0", "1.10",
|
{"snapshots.home.exclude.0", "1.10",
|
||||||
func(cfg *config.Config) string { return cfg.Snapshots["home"].Exclude[0] }},
|
func(cfg *config.Config) string { return cfg.Snapshots["home"].Exclude[0] }},
|
||||||
}
|
}
|
||||||
@@ -134,6 +136,22 @@ func TestConfigSetStringLooksLikeNumber(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestConfigSetNonUTF8Path checks that config set still accepts a value that
|
||||||
|
// is not valid UTF-8, such as a path with a Latin-1 file name, and that
|
||||||
|
// config.Load returns it unchanged.
|
||||||
|
func TestConfigSetNonUTF8Path(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
const dir = "/srv/caf\xe9"
|
||||||
|
|
||||||
|
cfg := loadAfterConfigSet(t, "snapshots.home.paths.0", dir)
|
||||||
|
|
||||||
|
got := cfg.Snapshots["home"].Paths[0]
|
||||||
|
if got != dir {
|
||||||
|
t.Errorf("snapshots.home.paths.0 = %q, want %q", got, dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestConfigSetNumberStaysNumber checks that a number set for an integer
|
// TestConfigSetNumberStaysNumber checks that a number set for an integer
|
||||||
// setting is still read as a number, not as a quoted string.
|
// setting is still read as a number, not as a quoted string.
|
||||||
func TestConfigSetNumberStaysNumber(t *testing.T) {
|
func TestConfigSetNumberStaysNumber(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user