@@ -366,4 +366,56 @@ void ignoreUnresolvableNestedPlaceholdersIsConfigurable() {
366
366
.withMessageContaining ("Could not resolve placeholder 'bogus' in value \" ${p1}:${p2}:${bogus}\" " );
367
367
}
368
368
369
+ @ Test
370
+ void escapedPlaceholders_areNotEvaluated () {
371
+ testProperties .put ("prop1" , "value1" );
372
+ testProperties .put ("prop2" , "value2\\ ${prop1}" );
373
+
374
+ assertThat (propertyResolver .getProperty ("prop2" )).isEqualTo ("value2${prop1}" );
375
+ }
376
+
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" );
382
+
383
+ assertThat (propertyResolver .getProperty ("complex" )).isEqualTo ("start${prop1}middle${prop2}end" );
384
+ }
385
+
386
+ @ Test
387
+ void doubleBackslashes_areProcessedCorrectly () {
388
+ testProperties .put ("prop1" , "value1" );
389
+ testProperties .put ("doubleEscaped" , "value2\\ \\ ${prop1}" );
390
+
391
+ assertThat (propertyResolver .getProperty ("doubleEscaped" )).isEqualTo ("value2\\ ${prop1}" );
392
+ }
393
+
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 );
404
+
405
+ assertThat (pr .getProperty ("nested" )).isEqualTo ("prefix-${p1}-v2" );
406
+ }
407
+
408
+
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 );
417
+
418
+ assertThat (resolver .getProperty ("charseq" )).isEqualTo ("prefix-${p1}" );
419
+ }
420
+
369
421
}
0 commit comments