
Author: ceki Date: Tue Mar 4 16:48:11 2008 New Revision: 1627 Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/OptionHelperTest.java Log: - undefined substitution variables are now marked as _IS_UNDEFINED Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java ============================================================================== --- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java (original) +++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/OptionHelper.java Tue Mar 4 16:48:11 2008 @@ -9,8 +9,6 @@ */ package ch.qos.logback.core.util; -import java.util.Map; - import ch.qos.logback.core.Context; import ch.qos.logback.core.CoreGlobal; @@ -71,7 +69,8 @@ final static char DELIM_STOP = '}'; final static int DELIM_START_LEN = 2; final static int DELIM_STOP_LEN = 1; - + final static String _IS_UNDEFINED = "_IS_UNDEFINED"; + /** * Perform variable substitution in string <code>val</code> from the values * of keys found in context property map, and if that fails, then in the @@ -185,6 +184,9 @@ // x2=${x1} String recursiveReplacement = substVars(replacement, context); sbuf.append(recursiveReplacement); + } else { + // if we could not find a replacement, then signal the error + sbuf.append(key+"_IS_UNDEFINED"); } i = k + DELIM_STOP_LEN; Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/OptionHelperTest.java ============================================================================== --- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/OptionHelperTest.java (original) +++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/util/OptionHelperTest.java Tue Mar 4 16:48:11 2008 @@ -28,26 +28,33 @@ super.tearDown(); } - public void testSubstVarsNoSubstitution() { - String noSubst = "testing if it works"; - - String result = OptionHelper.substVars(noSubst, null); + public void testLiteral() { + String noSubst = "hello world"; + String result = OptionHelper.substVars(noSubst, context); assertEquals(noSubst, result); } - + + + public void testUndefinedValues() { + String withUndefinedValues = "${axyz}"; + + String result = OptionHelper.substVars(withUndefinedValues, context); + assertEquals("axyz"+OptionHelper._IS_UNDEFINED, result); + } + public void testSubstVarsVariableNotClosed() { String noSubst = "testing if ${v1 works"; try { @SuppressWarnings("unused") - String result = OptionHelper.substVars(noSubst, null); + String result = OptionHelper.substVars(noSubst, context); fail(); } catch (IllegalArgumentException e) { //ok } } - public void testSubstVarsPrimaryOnly() { + public void testSubstVarsContextOnly() { context.putProperty("v1", "if"); context.putProperty("v2", "works");