mirror of
https://github.com/lightbend/config.git
synced 2025-03-23 07:40:25 +08:00
Unquote keys with hyphen when rendering, fixes #83
This commit is contained in:
parent
e85a54e4a1
commit
d3f638f2c0
@ -78,8 +78,10 @@ final public class ConfigImplUtil {
|
||||
if (s.length() == 0)
|
||||
return renderJsonString(s);
|
||||
|
||||
// if it starts with a hyphen or number, we have to quote
|
||||
// to ensure we end up with a string and not a number
|
||||
int first = s.codePointAt(0);
|
||||
if (Character.isDigit(first))
|
||||
if (Character.isDigit(first) || first == '-')
|
||||
return renderJsonString(s);
|
||||
|
||||
if (s.startsWith("include") || s.startsWith("true") || s.startsWith("false")
|
||||
@ -89,7 +91,7 @@ final public class ConfigImplUtil {
|
||||
// only unquote if it's pure alphanumeric
|
||||
for (int i = 0; i < s.length(); ++i) {
|
||||
char c = s.charAt(i);
|
||||
if (!(Character.isLetter(c) || Character.isDigit(c)))
|
||||
if (!(Character.isLetter(c) || Character.isDigit(c) || c == '-'))
|
||||
return renderJsonString(s);
|
||||
}
|
||||
|
||||
|
7
config/src/test/resources/test11.conf
Normal file
7
config/src/test/resources/test11.conf
Normal file
@ -0,0 +1,7 @@
|
||||
// this checks quoting of strings that could be numbers, when we render
|
||||
|
||||
"10" = "42"
|
||||
"-10" = "-42"
|
||||
foo-bar = bar-baz
|
||||
"---" = "------"
|
||||
a- = b-
|
Loading…
Reference in New Issue
Block a user