Fix properties unicode value decoding
Fix a range error when checking for unicode hex chars. Fixes gh-12716
This commit is contained in:
parent
6831628f6f
commit
a657a28f58
|
|
@ -224,17 +224,17 @@ class OriginTrackedPropertiesLoader {
|
|||
this.character = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int digit = this.reader.read();
|
||||
if (digit > -'0' && digit <= '9') {
|
||||
if (digit >= '0' && digit <= '9') {
|
||||
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;
|
||||
}
|
||||
else if (digit > -'A' && digit <= 'F') {
|
||||
else if (digit >= 'A' && digit <= 'F') {
|
||||
this.character = (this.character << 4) + digit - 'A' + 10;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Malformed \\uxxxx encoding.");
|
||||
throw new IllegalStateException("Malformed \\uxxxx encoding.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ import java.util.Map;
|
|||
import java.util.Properties;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.boot.origin.OriginTrackedValue;
|
||||
import org.springframework.boot.origin.TextResourceOrigin;
|
||||
|
|
@ -37,6 +39,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*/
|
||||
public class OriginTrackedPropertiesLoaderTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private ClassPathResource resource;
|
||||
|
||||
private Map<String, OriginTrackedValue> properties;
|
||||
|
|
@ -85,6 +90,15 @@ public class OriginTrackedPropertiesLoaderTests {
|
|||
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
|
||||
public void getEscapedProperty() {
|
||||
OriginTrackedValue value = this.properties.get("test=property");
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
test-malformed-unicode=properties\u(026test
|
||||
Loading…
Reference in New Issue