Unquote keys with hyphen when rendering, fixes #83

This commit is contained in:
Havoc Pennington 2013-09-19 17:37:04 -04:00
parent e85a54e4a1
commit d3f638f2c0
2 changed files with 11 additions and 2 deletions

View File

@ -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);
}

View 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-