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

Error while parsing configuration when dot is used in key or value #47

Open
donglinjy opened this issue Dec 18, 2023 · 3 comments
Open

Comments

@donglinjy
Copy link

I will fail to load string configure as below, with error error while parsing configuration: missing comma! at: 4:13, values should have comma or ASCII newline ('\n') between them.

The root cause may be because text scanner will parse 2.2.0 into 2.2 and .0, and will parse c-f1.2g into c-f1, .2, and g.

	hoconString := `
		    key1 {
			  a = "a"
			  b = 2.2.0
			  c-f1.2g = "ok"
		    }`

	_, err := hocon.ParseString(hoconString)
	if err != nil {
		log.Println("error while parsing configuration: ", err)
	}
@gurkankaymak
Copy link
Owner

Hi @donglinjy, thanks for reporting the issue.
Yeah, the root of the issue is that the Golang text scanner parses as you described ('2.2.0' into '2.2' and '.0'). I'll look for a solution. In the meantime, you can use double quotes

key1 {
    a = "a"
    b = "2.2.0"
    "c-f1.2g" = "ok"
}

@donglinjy
Copy link
Author

Hi @donglinjy, thanks for reporting the issue. Yeah, the root of the issue is that the Golang text scanner parses as you described ('2.2.0' into '2.2' and '.0'). I'll look for a solution. In the meantime, you can use double quotes

key1 {
    a = "a"
    b = "2.2.0"
    "c-f1.2g" = "ok"
}

Thanks. Based on what I tried, to work around it, for the issue in value like 2.2.0, we can double quote it. But for key like c-f1.2g, will need to quote each parts split by . as blow, or the config loading will succeed, but it won't allow you to read config like GetString("key1.c-f1.2g").

    a = "a"
    b = "2.2.0"
    "c-f1"."2g" = "ok"
}

@gurkankaymak
Copy link
Owner

You're right, I didn't realize 'c-f1.2g' is nested, thought of it as a single key. In fact you can also just double quote the last part like c-f1."2g"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants