Commit a657a28f authored by Phillip Webb's avatar Phillip Webb

Fix properties unicode value decoding

Fix a range error when checking for unicode hex chars.

Fixes gh-12716
parent 6831628f
...@@ -224,17 +224,17 @@ class OriginTrackedPropertiesLoader { ...@@ -224,17 +224,17 @@ class OriginTrackedPropertiesLoader {
this.character = 0; this.character = 0;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
int digit = this.reader.read(); int digit = this.reader.read();
if (digit > -'0' && digit <= '9') { if (digit >= '0' && digit <= '9') {
this.character = (this.character << 4) + digit - '0'; this.character = (this.character << 4) + digit - '0';
} }
else if (digit > -'a' && digit <= 'f') { else if (digit >= 'a' && digit <= 'f') {
this.character = (this.character << 4) + digit - 'a' + 10; this.character = (this.character << 4) + digit - 'a' + 10;
} }
else if (digit > -'A' && digit <= 'F') { else if (digit >= 'A' && digit <= 'F') {
this.character = (this.character << 4) + digit - 'A' + 10; this.character = (this.character << 4) + digit - 'A' + 10;
} }
else { else {
throw new IllegalArgumentException("Malformed \\uxxxx encoding."); throw new IllegalStateException("Malformed \\uxxxx encoding.");
} }
} }
} }
......
...@@ -20,7 +20,9 @@ import java.util.Map; ...@@ -20,7 +20,9 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.boot.origin.OriginTrackedValue; import org.springframework.boot.origin.OriginTrackedValue;
import org.springframework.boot.origin.TextResourceOrigin; import org.springframework.boot.origin.TextResourceOrigin;
...@@ -37,6 +39,9 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -37,6 +39,9 @@ import static org.assertj.core.api.Assertions.assertThat;
*/ */
public class OriginTrackedPropertiesLoaderTests { public class OriginTrackedPropertiesLoaderTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private ClassPathResource resource; private ClassPathResource resource;
private Map<String, OriginTrackedValue> properties; private Map<String, OriginTrackedValue> properties;
...@@ -85,6 +90,15 @@ public class OriginTrackedPropertiesLoaderTests { ...@@ -85,6 +90,15 @@ public class OriginTrackedPropertiesLoaderTests {
assertThat(getLocation(value)).isEqualTo("12:14"); assertThat(getLocation(value)).isEqualTo("12:14");
} }
@Test
public void getMalformedUnicodeProperty() throws Exception {
// gh-2716
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Malformed \\uxxxx encoding");
new OriginTrackedPropertiesLoader(new ClassPathResource(
"test-properties-malformed-unicode.properties", getClass())).load();
}
@Test @Test
public void getEscapedProperty() { public void getEscapedProperty() {
OriginTrackedValue value = this.properties.get("test=property"); OriginTrackedValue value = this.properties.get("test=property");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment