Skip to content

Commit 4080010

Browse files
committed
feat: partially revert #1387
1387 introduced a rather serious breaking change that's causing pain throughout the community. Even though it fixed a buggy behavior the previous one was still useful to a lot of people. This change introduces a way to revert back to that old behavior. Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
1 parent 961c396 commit 4080010

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

internal/features/1387.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build !viper_1387
2+
// +build !viper_1387
3+
4+
package features
5+
6+
// Revert1387 reverts the behavior introduced in #1387.
7+
var Revert1387 = false

internal/features/1387_.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//go:build viper_1387
2+
// +build viper_1387
3+
4+
package features
5+
6+
// Revert1387 reverts the behavior introduced in #1387.
7+
var Revert1387 = true

internal/features/doc.go

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package features allows toggling features in Viper based on build tags.
2+
package features

util.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"unicode"
2020

2121
"github.com/spf13/cast"
22+
23+
"github.com/spf13/viper/internal/features"
2224
)
2325

2426
// ConfigParseError denotes failing to parse configuration file.
@@ -79,8 +81,11 @@ func insensitiviseVal(val interface{}) interface{} {
7981
// nested map: recursively insensitivise
8082
insensitiviseMap(val.(map[string]interface{}))
8183
case []interface{}:
82-
// nested array: recursively insensitivise
83-
insensitiveArray(val.([]interface{}))
84+
// deprecated, drop in Viper v2
85+
if !features.Revert1387 {
86+
// nested array: recursively insensitivise
87+
insensitiveArray(val.([]interface{}))
88+
}
8489
}
8590
return val
8691
}

viper_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/stretchr/testify/assert"
3232
"github.com/stretchr/testify/require"
3333

34+
"github.com/spf13/viper/internal/features"
3435
"github.com/spf13/viper/internal/testutil"
3536
)
3637

@@ -2672,6 +2673,22 @@ func TestSliceIndexAccess(t *testing.T) {
26722673
assert.Equal(t, "The Expanse", v.GetString("tv.0.title_i18n.USA"))
26732674
assert.Equal(t, "エクスパンス -巨獣めざめる-", v.GetString("tv.0.title_i18n.Japan"))
26742675

2676+
var expectedtitlei18n map[string]any
2677+
2678+
if features.Revert1387 {
2679+
expectedtitlei18n = map[string]any{
2680+
"USA": "The Expanse",
2681+
"Japan": "エクスパンス -巨獣めざめる-",
2682+
}
2683+
} else {
2684+
expectedtitlei18n = map[string]any{
2685+
"usa": "The Expanse",
2686+
"japan": "エクスパンス -巨獣めざめる-",
2687+
}
2688+
}
2689+
2690+
assert.Equal(t, expectedtitlei18n, v.GetStringMap("tv.0.title_i18n"))
2691+
26752692
// Test for index out of bounds
26762693
assert.Equal(t, "", v.GetString("tv.0.seasons.2.first_released"))
26772694

0 commit comments

Comments
 (0)