| 
28 | 28 |  * @since 1.0  | 
29 | 29 |  */  | 
30 | 30 | public class EnvironmentPropertySource extends MapPropertySource {  | 
 | 31 | +    /**  | 
 | 32 | +     * Converts list elemtents defined as _0 or _0_ into names that the resolver can understand; i.e., [0].  | 
 | 33 | +     */  | 
 | 34 | +    private static final String LIST_CONVERTER_REGEX = "_([0-9]{1,2})(?:_|$)";  | 
31 | 35 | 
 
  | 
32 | 36 |     /**  | 
33 | 37 |      * The position of the loader.  | 
@@ -77,20 +81,20 @@ static Map getEnv(@Nullable List<String> includes, @Nullable List<String> exclud  | 
77 | 81 |     }  | 
78 | 82 | 
 
  | 
79 | 83 |     static Map getEnv(Map<String, String> env, @Nullable List<String> includes, @Nullable List<String> excludes) {  | 
80 |  | -        if (includes != null || excludes != null) {  | 
81 |  | -            Map<String, String> result = new HashMap<>();  | 
82 |  | -            for (Map.Entry<String, String> entry : env.entrySet()) {  | 
83 |  | -                String envVar = entry.getKey();  | 
84 |  | -                if (excludes != null && excludes.contains(envVar)) {  | 
85 |  | -                    continue;  | 
86 |  | -                }  | 
87 |  | -                if (includes != null && !includes.contains(envVar)) {  | 
88 |  | -                    continue;  | 
89 |  | -                }  | 
90 |  | -                result.put(envVar, entry.getValue());  | 
 | 84 | +        Map<String, String> result = new HashMap<>();  | 
 | 85 | +        for (Map.Entry<String, String> entry : env.entrySet()) {  | 
 | 86 | +            String envVar = entry.getKey();  | 
 | 87 | +            if (excludes != null && excludes.contains(envVar)) {  | 
 | 88 | +                continue;  | 
 | 89 | +            }  | 
 | 90 | +            if (includes != null && !includes.contains(envVar)) {  | 
 | 91 | +                continue;  | 
91 | 92 |             }  | 
92 |  | -            return result;  | 
 | 93 | +              | 
 | 94 | +            String convertedEnvVar = envVar.replaceAll(LIST_CONVERTER_REGEX, "[$1]");  | 
 | 95 | +              | 
 | 96 | +            result.put(convertedEnvVar, entry.getValue());  | 
93 | 97 |         }  | 
94 |  | -        return env;  | 
 | 98 | +        return result;  | 
95 | 99 |     }  | 
96 | 100 | }  | 
0 commit comments