From 1653cc8e8899d8a915623f3e6273596189e9122b Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Thu, 19 Sep 2013 11:41:58 -0400 Subject: [PATCH] Don't add multiple spaces in front of comments, fixes #87 --- .../com/typesafe/config/impl/SimpleConfigObject.java | 4 +++- .../test/scala/com/typesafe/config/impl/ConfigTest.scala | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java b/config/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java index fb3ac60d..1977bd1b 100644 --- a/config/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java +++ b/config/src/main/java/com/typesafe/config/impl/SimpleConfigObject.java @@ -390,7 +390,9 @@ final class SimpleConfigObject extends AbstractConfigObject implements Serializa if (options.getComments()) { for (String comment : v.origin().comments()) { indent(sb, indent + 1, options); - sb.append("# "); + sb.append("#"); + if (!comment.startsWith(" ")) + sb.append(' '); sb.append(comment); sb.append("\n"); } diff --git a/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala b/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala index 27235172..aa11d41d 100644 --- a/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala +++ b/config/src/test/scala/com/typesafe/config/impl/ConfigTest.scala @@ -1059,6 +1059,15 @@ class ConfigTest extends TestUtils { throw e } } + // rendering repeatedly should not make the file different (e.g. shouldn't make it longer) + // unless the debug comments are in there + if (!renderOptions.getOriginComments()) { + val renderedAgain = resolvedParsed.root.render(renderOptions) + // TODO the strings should be THE SAME not just the same length, + // but there's a bug right now that sometimes object keys seem to + // be re-ordered. Need to fix. + assertEquals("render changed, resolved options=" + renderOptions, resolvedRender.length, renderedAgain.length) + } } } }