File tree 5 files changed +40
-2
lines changed
5 files changed +40
-2
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
1
+ // Package features allows toggling features in Viper based on build tags.
2
+ package features
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ import (
19
19
"unicode"
20
20
21
21
"github.com/spf13/cast"
22
+
23
+ "github.com/spf13/viper/internal/features"
22
24
)
23
25
24
26
// ConfigParseError denotes failing to parse configuration file.
@@ -79,8 +81,11 @@ func insensitiviseVal(val interface{}) interface{} {
79
81
// nested map: recursively insensitivise
80
82
insensitiviseMap (val .(map [string ]interface {}))
81
83
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
+ }
84
89
}
85
90
return val
86
91
}
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ import (
31
31
"github.com/stretchr/testify/assert"
32
32
"github.com/stretchr/testify/require"
33
33
34
+ "github.com/spf13/viper/internal/features"
34
35
"github.com/spf13/viper/internal/testutil"
35
36
)
36
37
@@ -2672,6 +2673,22 @@ func TestSliceIndexAccess(t *testing.T) {
2672
2673
assert .Equal (t , "The Expanse" , v .GetString ("tv.0.title_i18n.USA" ))
2673
2674
assert .Equal (t , "エクスパンス -巨獣めざめる-" , v .GetString ("tv.0.title_i18n.Japan" ))
2674
2675
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
+
2675
2692
// Test for index out of bounds
2676
2693
assert .Equal (t , "" , v .GetString ("tv.0.seasons.2.first_released" ))
2677
2694
You can’t perform that action at this time.
0 commit comments