Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cannot write hidden file without extension #1064

Merged
merged 2 commits into from Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion viper.go
Expand Up @@ -1537,7 +1537,7 @@ func (v *Viper) writeConfig(filename string, force bool) error {
var configType string

ext := filepath.Ext(filename)
if ext != "" {
if ext != "" && ext != filepath.Base(filename) {
configType = ext[1:]
} else {
configType = v.configType
Expand Down
17 changes: 17 additions & 0 deletions viper_test.go
Expand Up @@ -1690,6 +1690,23 @@ func TestSafeWriteConfigAsWithExistingFile(t *testing.T) {
assert.True(t, ok, "Expected ConfigFileAlreadyExistsError")
}

func TestWriteHiddenFile(t *testing.T) {
v := New()
fs := afero.NewMemMapFs()
fs.Create("/test/.config")
v.SetFs(fs)

v.SetConfigName(".config")
v.SetConfigType("yaml")
v.AddConfigPath("/test")

err := v.ReadInConfig()
require.NoError(t, err)

err = v.WriteConfig()
require.NoError(t, err)
}

var yamlMergeExampleTgt = []byte(`
hello:
pop: 37890
Expand Down