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

TOML keys are not read if they contain a dot #1143

Open
greg-szabo opened this issue May 28, 2021 · 1 comment
Open

TOML keys are not read if they contain a dot #1143

greg-szabo opened this issue May 28, 2021 · 1 comment
Labels
kind/bug Something isn't working

Comments

@greg-szabo
Copy link

Expected behavior (what you expected to happen):
Unquoted TOML entries with a dot should be read properly:

[section1]
la.la="one"
[section2]
"la.la"="two"

section1.la.la should read one.

Actual behavior (what actually happened):
Only section2.la.la will be available, not section1.la.la contrary to the TOML definition.

Repl.it link:

https://replit.com/@gregszabo/TOMLExample3

Code reproducing the issue:

package main

import (
	"bytes"
	"fmt"
	"github.com/spf13/viper"
)

func main() {

var tomlExample1 = []byte(`
[something]
la="one"
`)

var tomlExample2 = []byte(`
[something]
la.la="two"
`)

var tomlExample3 = []byte(`
[something]
"la.la"="three"
`)


	viper.SetConfigType("toml")

	viper.ReadConfig(bytes.NewBuffer(tomlExample1))
	fmt.Printf("%v\n",viper.AllKeys())

	viper.ReadConfig(bytes.NewBuffer(tomlExample2))
	fmt.Printf("%v\n",viper.AllKeys())

	viper.ReadConfig(bytes.NewBuffer(tomlExample3))
	fmt.Printf("%v\n",viper.AllKeys())

  // From https://toml.io/en/v1.0.0#keys
  //   Dotted keys are a sequence of bare or quoted keys joined with a dot. This allows for grouping similar properties together
  // Output:
  //   [something.la]
  //   []
  //   [something.la.la]
  // Expected output:
  //   [something.la]
  //   [something.la.la]
  //   [something.la.la]
}

Environment:

  • Viper version: v1.7.1
  • Config source: file
  • File format: TOML

Anything else we should know?:

@greg-szabo greg-szabo added the kind/bug Something isn't working label May 28, 2021
@github-actions
Copy link

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news,
either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant