an explicit { HOME : null } should block lookup of ${HOME} in the environment.

This commit is contained in:
Havoc Pennington 2011-11-17 00:56:44 -05:00
parent 5f6f718566
commit 159bec9d03
2 changed files with 23 additions and 4 deletions

View File

@ -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;
}

View File

@ -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._