From 9348bf2132b070189dff6f502468143f18cb314f Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 25 Feb 2015 23:29:21 -0500 Subject: [PATCH] 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. --- .../src/main/java/com/typesafe/config/impl/Path.java | 10 +--------- .../test/scala/com/typesafe/config/impl/PathTest.scala | 10 +++++----- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/config/src/main/java/com/typesafe/config/impl/Path.java b/config/src/main/java/com/typesafe/config/impl/Path.java index c3b8f39e..11952091 100644 --- a/config/src/main/java/com/typesafe/config/impl/Path.java +++ b/config/src/main/java/com/typesafe/config/impl/Path.java @@ -167,15 +167,7 @@ final class Path { if (length == 0) return false; - // if the path starts with something that could be a number, - // 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) { + for (int i = 0; i < length; ++i) { char c = s.charAt(i); if (Character.isLetterOrDigit(c) || c == '-' || c == '_') diff --git a/config/src/test/scala/com/typesafe/config/impl/PathTest.scala b/config/src/test/scala/com/typesafe/config/impl/PathTest.scala index ccf05a94..bc8bfd1d 100644 --- a/config/src/test/scala/com/typesafe/config/impl/PathTest.scala +++ b/config/src/test/scala/com/typesafe/config/impl/PathTest.scala @@ -56,9 +56,9 @@ class PathTest extends TestUtils { RenderTest("foo-bar", path("foo-bar")), RenderTest("foo_bar", path("foo_bar")), // starts with hyphen - RenderTest("\"-foo\"", path("-foo")), + RenderTest("-foo", path("-foo")), // starts with number - RenderTest("\"10foo\"", path("10foo")), + RenderTest("10foo", path("10foo")), // empty elements RenderTest("\"\".\"\"", path("", "")), // internal space @@ -66,10 +66,10 @@ class PathTest extends TestUtils { // leading and trailing spaces RenderTest("\" foo \"", path(" foo ")), // trailing space only - RenderTest("\"foo \"", path("foo "))) + RenderTest("\"foo \"", path("foo ")), // numbers with decimal points - RenderTest("1.2", path("1", "2")) - RenderTest("1.2.3.4", path("1", "2", "3", "4")) + RenderTest("1.2", path("1", "2")), + RenderTest("1.2.3.4", path("1", "2", "3", "4"))) for (t <- tests) { assertEquals(t.expected, t.path.render())