mirror of
https://github.com/spf13/viper.git
synced 2024-04-21 12:31:38 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40800105e2 |
@@ -0,0 +1,7 @@
|
||||
//go:build !viper_1387
|
||||
// +build !viper_1387
|
||||
|
||||
package features
|
||||
|
||||
// Revert1387 reverts the behavior introduced in #1387.
|
||||
var Revert1387 = false
|
||||
@@ -0,0 +1,7 @@
|
||||
//go:build viper_1387
|
||||
// +build viper_1387
|
||||
|
||||
package features
|
||||
|
||||
// Revert1387 reverts the behavior introduced in #1387.
|
||||
var Revert1387 = true
|
||||
@@ -0,0 +1,2 @@
|
||||
// Package features allows toggling features in Viper based on build tags.
|
||||
package features
|
||||
@@ -19,6 +19,8 @@ import (
|
||||
"unicode"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
|
||||
"github.com/spf13/viper/internal/features"
|
||||
)
|
||||
|
||||
// ConfigParseError denotes failing to parse configuration file.
|
||||
@@ -79,8 +81,11 @@ func insensitiviseVal(val interface{}) interface{} {
|
||||
// nested map: recursively insensitivise
|
||||
insensitiviseMap(val.(map[string]interface{}))
|
||||
case []interface{}:
|
||||
// nested array: recursively insensitivise
|
||||
insensitiveArray(val.([]interface{}))
|
||||
// deprecated, drop in Viper v2
|
||||
if !features.Revert1387 {
|
||||
// nested array: recursively insensitivise
|
||||
insensitiveArray(val.([]interface{}))
|
||||
}
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/spf13/viper/internal/features"
|
||||
"github.com/spf13/viper/internal/testutil"
|
||||
)
|
||||
|
||||
@@ -2672,6 +2673,22 @@ func TestSliceIndexAccess(t *testing.T) {
|
||||
assert.Equal(t, "The Expanse", v.GetString("tv.0.title_i18n.USA"))
|
||||
assert.Equal(t, "エクスパンス -巨獣めざめる-", v.GetString("tv.0.title_i18n.Japan"))
|
||||
|
||||
var expectedtitlei18n map[string]any
|
||||
|
||||
if features.Revert1387 {
|
||||
expectedtitlei18n = map[string]any{
|
||||
"USA": "The Expanse",
|
||||
"Japan": "エクスパンス -巨獣めざめる-",
|
||||
}
|
||||
} else {
|
||||
expectedtitlei18n = map[string]any{
|
||||
"usa": "The Expanse",
|
||||
"japan": "エクスパンス -巨獣めざめる-",
|
||||
}
|
||||
}
|
||||
|
||||
assert.Equal(t, expectedtitlei18n, v.GetStringMap("tv.0.title_i18n"))
|
||||
|
||||
// Test for index out of bounds
|
||||
assert.Equal(t, "", v.GetString("tv.0.seasons.2.first_released"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user