Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected Map<String, Object> decrypt(TextEncryptor encryptor, PropertySources p
for (PropertySource<?> propertySource : propertySources) {
if (propertySource instanceof EnumerablePropertySource<?> enumerable) {
for (String propertyName : enumerable.getPropertyNames()) {
if (visitor.isVisited(propertyName)) {
if (propertyName == null || visitor.isVisited(propertyName)) {
continue;
}

Expand Down Expand Up @@ -136,7 +136,7 @@ private IndexedValue getPropertyValues(EnumerablePropertySource<?> source, TextE
boolean containsDecrypted = false;
Map<String, Object> elements = new HashMap<>();
for (String name : source.getPropertyNames()) {
if (COLLECTION_PROPERTY.matcher(name).matches() && name.startsWith(prefix)) {
if (name != null && COLLECTION_PROPERTY.matcher(name).matches() && name.startsWith(prefix)) {
var value = getPropertyValue(source, encryptor, name);
elements.put(name, value.value);
if (value.isDecrypted) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.cloud.bootstrap.encrypt;

import java.util.HashMap;
import java.util.Map;

import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -230,6 +231,20 @@ void indexedPropertiesWithSimilarNamesAreHandledCorrectly() {
then(environment.getProperty("fooBar[0]")).isEqualTo("updated");
}

@Test
void nullKeyedPropertyNamesAreIgnored() {
// Simulates OS environment blocks (seen on Linux/Docker) that can contain
// entries with a null key.
Map<String, Object> sourceWithNullKey = new HashMap<>();
sourceWithNullKey.put(null, "some-value");
sourceWithNullKey.put("foo", "{cipher}bar");
environment.getPropertySources().addFirst(new MapPropertySource("source-1", sourceWithNullKey));

decrypt();

then(environment.getProperty("foo")).isEqualTo("bar");
}

private void decrypt() {
decrypt(Encryptors.noOpText());
}
Expand Down
Loading