Skip to content

Commit 348b4cd

Browse files
committed
Polish contribution
See gh-34720
1 parent 9b52cfd commit 348b4cd

File tree

1 file changed

+39
-41
lines changed

1 file changed

+39
-41
lines changed

spring-core/src/test/java/org/springframework/core/env/PropertySourcesPropertyResolverTests.java

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
2121
import java.util.Properties;
2222

2323
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Nested;
2425
import org.junit.jupiter.api.Test;
2526

2627
import org.springframework.core.convert.ConverterNotFoundException;
@@ -366,56 +367,53 @@ void ignoreUnresolvableNestedPlaceholdersIsConfigurable() {
366367
.withMessageContaining("Could not resolve placeholder 'bogus' in value \"${p1}:${p2}:${bogus}\"");
367368
}
368369

369-
@Test
370-
void escapedPlaceholders_areNotEvaluated() {
371-
testProperties.put("prop1", "value1");
372-
testProperties.put("prop2", "value2\\${prop1}");
373370

374-
assertThat(propertyResolver.getProperty("prop2")).isEqualTo("value2${prop1}");
375-
}
371+
@Nested
372+
class EscapedPlaceholderTests {
376373

377-
@Test
378-
void multipleEscapedPlaceholders_arePreserved() {
379-
testProperties.put("prop1", "value1");
380-
testProperties.put("prop2", "value2");
381-
testProperties.put("complex", "start\\${prop1}middle\\${prop2}end");
374+
@Test // gh-34720
375+
void escapedPlaceholdersAreNotEvaluated() {
376+
testProperties.put("prop1", "value1");
377+
testProperties.put("prop2", "value2\\${prop1}");
382378

383-
assertThat(propertyResolver.getProperty("complex")).isEqualTo("start${prop1}middle${prop2}end");
384-
}
379+
assertThat(propertyResolver.getProperty("prop2")).isEqualTo("value2${prop1}");
380+
}
385381

386-
@Test
387-
void doubleBackslashes_areProcessedCorrectly() {
388-
testProperties.put("prop1", "value1");
389-
testProperties.put("doubleEscaped", "value2\\\\${prop1}");
382+
@Test // gh-34720
383+
void escapedPlaceholdersAreNotEvaluatedWithCharSequenceValues() {
384+
testProperties.put("prop1", "value1");
385+
testProperties.put("prop2", new StringBuilder("value2\\${prop1}"));
390386

391-
assertThat(propertyResolver.getProperty("doubleEscaped")).isEqualTo("value2\\${prop1}");
392-
}
387+
assertThat(propertyResolver.getProperty("prop2")).isEqualTo("value2${prop1}");
388+
}
393389

394-
@Test
395-
void escapedPlaceholdersInNestedProperties() {
396-
MutablePropertySources ps = new MutablePropertySources();
397-
ps.addFirst(new MockPropertySource()
398-
.withProperty("p1", "v1")
399-
.withProperty("p2", "v2")
400-
.withProperty("escaped", "prefix-\\${p1}")
401-
.withProperty("nested", "${escaped}-${p2}")
402-
);
403-
ConfigurablePropertyResolver pr = new PropertySourcesPropertyResolver(ps);
390+
@Test // gh-34720
391+
void multipleEscapedPlaceholdersArePreserved() {
392+
testProperties.put("prop1", "value1");
393+
testProperties.put("prop2", "value2");
394+
testProperties.put("complex", "start\\${prop1}middle\\${prop2}end");
404395

405-
assertThat(pr.getProperty("nested")).isEqualTo("prefix-${p1}-v2");
406-
}
396+
assertThat(propertyResolver.getProperty("complex")).isEqualTo("start${prop1}middle${prop2}end");
397+
}
407398

399+
@Test // gh-34720
400+
void doubleBackslashesAreProcessedCorrectly() {
401+
testProperties.put("prop1", "value1");
402+
testProperties.put("doubleEscaped", "value2\\\\${prop1}");
408403

409-
@Test
410-
void escapedPlaceholders_withCharSequenceValues() {
411-
MutablePropertySources ps = new MutablePropertySources();
412-
ps.addFirst(new MockPropertySource()
413-
.withProperty("p1", "v1")
414-
.withProperty("charseq", new StringBuilder("prefix-\\${p1}"))
415-
);
416-
PropertyResolver resolver = new PropertySourcesPropertyResolver(ps);
404+
assertThat(propertyResolver.getProperty("doubleEscaped")).isEqualTo("value2\\${prop1}");
405+
}
406+
407+
@Test // gh-34720
408+
void escapedPlaceholdersInNestedPropertiesAreNotEvaluated() {
409+
testProperties.put("p1", "v1");
410+
testProperties.put("p2", "v2");
411+
testProperties.put("escaped", "prefix-\\${p1}");
412+
testProperties.put("nested", "${escaped}-${p2}");
413+
414+
assertThat(propertyResolver.getProperty("nested")).isEqualTo("prefix-${p1}-v2");
415+
}
417416

418-
assertThat(resolver.getProperty("charseq")).isEqualTo("prefix-${p1}");
419417
}
420418

421419
}

0 commit comments

Comments
 (0)