mirror of
https://github.com/lightbend/config.git
synced 2025-01-16 07:10:21 +08:00
Fix Path.render to avoid quoting elements starting with number char
This was supposed to be done earlier, but the test for it wasn't actually being run - it looked like it was in a list due to indentation, but in fact was not in the list. So Scalariform revealed the bug.
This commit is contained in:
parent
9d16f3bf61
commit
9348bf2132
@ -167,15 +167,7 @@ final class Path {
|
|||||||
if (length == 0)
|
if (length == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// if the path starts with something that could be a number,
|
for (int i = 0; i < length; ++i) {
|
||||||
// we need to quote it because the number could be invalid,
|
|
||||||
// for example it could be a hyphen with no digit afterward
|
|
||||||
// or the exponent "e" notation could be mangled.
|
|
||||||
char first = s.charAt(0);
|
|
||||||
if (!(Character.isLetter(first)))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
for (int i = 1; i < length; ++i) {
|
|
||||||
char c = s.charAt(i);
|
char c = s.charAt(i);
|
||||||
|
|
||||||
if (Character.isLetterOrDigit(c) || c == '-' || c == '_')
|
if (Character.isLetterOrDigit(c) || c == '-' || c == '_')
|
||||||
|
@ -56,9 +56,9 @@ class PathTest extends TestUtils {
|
|||||||
RenderTest("foo-bar", path("foo-bar")),
|
RenderTest("foo-bar", path("foo-bar")),
|
||||||
RenderTest("foo_bar", path("foo_bar")),
|
RenderTest("foo_bar", path("foo_bar")),
|
||||||
// starts with hyphen
|
// starts with hyphen
|
||||||
RenderTest("\"-foo\"", path("-foo")),
|
RenderTest("-foo", path("-foo")),
|
||||||
// starts with number
|
// starts with number
|
||||||
RenderTest("\"10foo\"", path("10foo")),
|
RenderTest("10foo", path("10foo")),
|
||||||
// empty elements
|
// empty elements
|
||||||
RenderTest("\"\".\"\"", path("", "")),
|
RenderTest("\"\".\"\"", path("", "")),
|
||||||
// internal space
|
// internal space
|
||||||
@ -66,10 +66,10 @@ class PathTest extends TestUtils {
|
|||||||
// leading and trailing spaces
|
// leading and trailing spaces
|
||||||
RenderTest("\" foo \"", path(" foo ")),
|
RenderTest("\" foo \"", path(" foo ")),
|
||||||
// trailing space only
|
// trailing space only
|
||||||
RenderTest("\"foo \"", path("foo ")))
|
RenderTest("\"foo \"", path("foo ")),
|
||||||
// numbers with decimal points
|
// numbers with decimal points
|
||||||
RenderTest("1.2", path("1", "2"))
|
RenderTest("1.2", path("1", "2")),
|
||||||
RenderTest("1.2.3.4", path("1", "2", "3", "4"))
|
RenderTest("1.2.3.4", path("1", "2", "3", "4")))
|
||||||
|
|
||||||
for (t <- tests) {
|
for (t <- tests) {
|
||||||
assertEquals(t.expected, t.path.render())
|
assertEquals(t.expected, t.path.render())
|
||||||
|
Loading…
Reference in New Issue
Block a user