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) + } } } }