|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2023 the original author or authors. |
| 2 | + * Copyright 2012-2024 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.
|
|
33 | 33 | * Tests for {@link ConfigurationPropertySourcesPropertyResolver}.
|
34 | 34 | *
|
35 | 35 | * @author Phillip Webb
|
| 36 | + * @author Yanming Zhou |
36 | 37 | */
|
37 | 38 | class ConfigurationPropertySourcesPropertyResolverTests {
|
38 | 39 |
|
@@ -113,6 +114,45 @@ void getPropertyAsTypeWhenHasPlaceholder() {
|
113 | 114 | assertThat(environment.getProperty("v2", Integer.class)).isOne();
|
114 | 115 | }
|
115 | 116 |
|
| 117 | + @Test // gh-34195 |
| 118 | + void resolveNestedPlaceholdersIfValueIsCharSequence() { |
| 119 | + CharSequence cs = new CharSequence() { |
| 120 | + |
| 121 | + static final String underlying = "${v1}"; |
| 122 | + |
| 123 | + @Override |
| 124 | + public int length() { |
| 125 | + return underlying.length(); |
| 126 | + } |
| 127 | + |
| 128 | + @Override |
| 129 | + public char charAt(int index) { |
| 130 | + return underlying.charAt(index); |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public CharSequence subSequence(int start, int end) { |
| 135 | + return underlying.subSequence(start, end); |
| 136 | + } |
| 137 | + |
| 138 | + @Override |
| 139 | + public String toString() { |
| 140 | + return underlying; |
| 141 | + } |
| 142 | + }; |
| 143 | + ResolverEnvironment environment = new ResolverEnvironment(); |
| 144 | + MockPropertySource propertySource = new MockPropertySource(); |
| 145 | + propertySource.withProperty("v1", "1"); |
| 146 | + propertySource.withProperty("v2", cs); |
| 147 | + environment.getPropertySources().addFirst(propertySource); |
| 148 | + assertThat(environment.getProperty("v2")).isEqualTo("1"); |
| 149 | + assertThat(environment.getProperty("v2", CharSequence.class)).isEqualTo("1"); |
| 150 | + assertThat(environment.getProperty("v2", Integer.class)).isOne(); |
| 151 | + |
| 152 | + // do not resolve to avoid ConverterNotFoundException |
| 153 | + assertThat(environment.getProperty("v2", cs.getClass())).isSameAs(cs); |
| 154 | + } |
| 155 | + |
116 | 156 | private CountingMockPropertySource createMockPropertySource(StandardEnvironment environment, boolean attach) {
|
117 | 157 | CountingMockPropertySource propertySource = new CountingMockPropertySource();
|
118 | 158 | propertySource.withProperty("spring", "boot");
|
|
0 commit comments