mirror of
https://github.com/lightbend/config.git
synced 2025-01-15 23:01:05 +08:00
an explicit { HOME : null } should block lookup of ${HOME} in the environment.
This commit is contained in:
parent
5f6f718566
commit
159bec9d03
@ -99,10 +99,6 @@ final class ConfigSubstitution extends AbstractConfigValue implements
|
||||
"peek or peekPath returned an unresolved substitution");
|
||||
}
|
||||
|
||||
if (result != null && result.valueType() == ConfigValueType.NULL) {
|
||||
result = null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import org.junit._
|
||||
import com.typesafe.config.ConfigValue
|
||||
import com.typesafe.config.ConfigException
|
||||
import com.typesafe.config.ConfigResolveOptions
|
||||
import com.typesafe.config.Config
|
||||
|
||||
class ConfigSubstitutionTest extends TestUtils {
|
||||
|
||||
@ -294,6 +295,28 @@ class ConfigSubstitutionTest extends TestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
def noFallbackToEnvIfValuesAreNull() {
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
// create a fallback object with all the env var names
|
||||
// set to null. we want to be sure this blocks
|
||||
// lookup in the environment. i.e. if there is a
|
||||
// { HOME : null } then ${HOME} should be null.
|
||||
val nullsMap = new java.util.HashMap[String, Object]
|
||||
for (k <- substEnvVarObject.keySet().asScala) {
|
||||
nullsMap.put(k.toUpperCase(), null);
|
||||
}
|
||||
val nulls = Config.fromMap(nullsMap, "nulls map")
|
||||
|
||||
val resolved = resolve(substEnvVarObject.withFallback(nulls))
|
||||
|
||||
for (k <- resolved.keySet().asScala) {
|
||||
assertNotNull(resolved.get(k))
|
||||
assertEquals(nullValue, resolved.get(k))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
def fallbackToEnvWhenRelativized() {
|
||||
import scala.collection.JavaConverters._
|
||||
|
Loading…
Reference in New Issue
Block a user