|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2024 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | import java.util.Properties;
|
22 | 22 |
|
23 | 23 | import org.junit.jupiter.api.BeforeEach;
|
| 24 | +import org.junit.jupiter.api.Nested; |
24 | 25 | import org.junit.jupiter.api.Test;
|
25 | 26 |
|
26 | 27 | import org.springframework.core.convert.ConverterNotFoundException;
|
@@ -366,56 +367,53 @@ void ignoreUnresolvableNestedPlaceholdersIsConfigurable() {
|
366 | 367 | .withMessageContaining("Could not resolve placeholder 'bogus' in value \"${p1}:${p2}:${bogus}\"");
|
367 | 368 | }
|
368 | 369 |
|
369 |
| - @Test |
370 |
| - void escapedPlaceholders_areNotEvaluated() { |
371 |
| - testProperties.put("prop1", "value1"); |
372 |
| - testProperties.put("prop2", "value2\\${prop1}"); |
373 | 370 |
|
374 |
| - assertThat(propertyResolver.getProperty("prop2")).isEqualTo("value2${prop1}"); |
375 |
| - } |
| 371 | + @Nested |
| 372 | + class EscapedPlaceholderTests { |
376 | 373 |
|
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}"); |
382 | 378 |
|
383 |
| - assertThat(propertyResolver.getProperty("complex")).isEqualTo("start${prop1}middle${prop2}end"); |
384 |
| - } |
| 379 | + assertThat(propertyResolver.getProperty("prop2")).isEqualTo("value2${prop1}"); |
| 380 | + } |
385 | 381 |
|
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}")); |
390 | 386 |
|
391 |
| - assertThat(propertyResolver.getProperty("doubleEscaped")).isEqualTo("value2\\${prop1}"); |
392 |
| - } |
| 387 | + assertThat(propertyResolver.getProperty("prop2")).isEqualTo("value2${prop1}"); |
| 388 | + } |
393 | 389 |
|
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"); |
404 | 395 |
|
405 |
| - assertThat(pr.getProperty("nested")).isEqualTo("prefix-${p1}-v2"); |
406 |
| - } |
| 396 | + assertThat(propertyResolver.getProperty("complex")).isEqualTo("start${prop1}middle${prop2}end"); |
| 397 | + } |
407 | 398 |
|
| 399 | + @Test // gh-34720 |
| 400 | + void doubleBackslashesAreProcessedCorrectly() { |
| 401 | + testProperties.put("prop1", "value1"); |
| 402 | + testProperties.put("doubleEscaped", "value2\\\\${prop1}"); |
408 | 403 |
|
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 | + } |
417 | 416 |
|
418 |
| - assertThat(resolver.getProperty("charseq")).isEqualTo("prefix-${p1}"); |
419 | 417 | }
|
420 | 418 |
|
421 | 419 | }
|
0 commit comments