diff --git a/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedPropertiesLoader.java b/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedPropertiesLoader.java index 2508fd6938f..be563a2388a 100644 --- a/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedPropertiesLoader.java +++ b/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedPropertiesLoader.java @@ -71,6 +71,7 @@ class OriginTrackedPropertiesLoader { StringBuilder buffer = new StringBuilder(); while (reader.read()) { String key = loadKey(buffer, reader).trim(); + System.out.println(key); if (expandLists && key.endsWith("[]")) { key = key.substring(0, key.length() - 2); int index = 0; @@ -160,11 +161,19 @@ class OriginTrackedPropertiesLoader { } public boolean read() throws IOException { + return read(false); + } + + public boolean read(boolean wrappedLine) throws IOException { this.escaped = false; this.character = this.reader.read(); this.columnNumber++; - skipLeadingWhitespace(); - skipComment(); + if (this.columnNumber == 0) { + skipLeadingWhitespace(); + if (!wrappedLine) { + skipComment(); + } + } if (this.character == '\\') { this.escaped = true; readEscaped(); @@ -176,11 +185,9 @@ class OriginTrackedPropertiesLoader { } private void skipLeadingWhitespace() throws IOException { - if (this.columnNumber == 0) { - while (isWhiteSpace()) { - this.character = this.reader.read(); - this.columnNumber++; - } + while (isWhiteSpace()) { + this.character = this.reader.read(); + this.columnNumber++; } } @@ -202,7 +209,7 @@ class OriginTrackedPropertiesLoader { } else if (this.character == '\n') { this.columnNumber = -1; - read(); + read(true); } else if (this.character == 'u') { readUnicode(); diff --git a/spring-boot/src/test/java/org/springframework/boot/env/OriginTrackedPropertiesLoaderTests.java b/spring-boot/src/test/java/org/springframework/boot/env/OriginTrackedPropertiesLoaderTests.java index dcb618df826..d1b5df7c9f3 100644 --- a/spring-boot/src/test/java/org/springframework/boot/env/OriginTrackedPropertiesLoaderTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/env/OriginTrackedPropertiesLoaderTests.java @@ -52,7 +52,7 @@ public class OriginTrackedPropertiesLoaderTests { Properties ours = new Properties(); new OriginTrackedPropertiesLoader(this.resource).load(false) .forEach((k, v) -> ours.put(k, v.getValue())); - assertThat(java).isEqualTo(ours); + assertThat(ours).isEqualTo(java); } @Test @@ -97,6 +97,20 @@ public class OriginTrackedPropertiesLoaderTests { assertThat(getLocation(value)).isEqualTo("16:19"); } + @Test + public void getPropertyWithBang() throws Exception { + OriginTrackedValue value = this.properties.get("test-bang-property"); + assertThat(getValue(value)).isEqualTo("foo!"); + assertThat(getLocation(value)).isEqualTo("34:20"); + } + + @Test + public void getPropertyWithValueComment() throws Exception { + OriginTrackedValue value = this.properties.get("test-property-value-comment"); + assertThat(getValue(value)).isEqualTo("foo !bar #foo"); + assertThat(getLocation(value)).isEqualTo("36:29"); + } + @Test public void getPropertyWithCarriageReturn() throws Exception { OriginTrackedValue value = this.properties.get("test-return-property"); diff --git a/spring-boot/src/test/resources/org/springframework/boot/env/test-properties.properties b/spring-boot/src/test/resources/org/springframework/boot/env/test-properties.properties index 0e3f912f439..19dabb34fba 100644 --- a/spring-boot/src/test/resources/org/springframework/boot/env/test-properties.properties +++ b/spring-boot/src/test/resources/org/springframework/boot/env/test-properties.properties @@ -31,3 +31,9 @@ language[pascal]=Lame test-multiline-immediate=\ foo !commented-two=bang\ +test-bang-property=foo! +another=bar +test-property-value-comment=foo \ +!bar #foo +test-multiline-immediate-bang=\ +!foo