carnold 2005/02/11 10:11:44 Modified: src/java/org/apache/log4j FileAppender.java PatternLayout.java src/java/org/apache/log4j/helpers OptionConverter.java src/java/org/apache/log4j/joran/action ParamAction.java tests/src/java/org/apache/log4j/helpers OptionSubstitutionTest.java tests/src/java/org/apache/log4j/xml DOMTestCase.java Added: tests/input/xml DOMTestCase2.xml tests/witness/xml dom.A1.2 dom.A2.2 Log: Bug 22894: Accept single backslashes in filenames in XML configs Revision Changes Path 1.48 +2 -1 logging-log4j/src/java/org/apache/log4j/FileAppender.java Index: FileAppender.java =================================================================== RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/FileAppender.java,v retrieving revision 1.47 retrieving revision 1.48 diff -u -r1.47 -r1.48 --- FileAppender.java 6 Jan 2005 17:03:11 -0000 1.47 +++ FileAppender.java 11 Feb 2005 18:11:44 -0000 1.48 @@ -19,6 +19,7 @@ import java.io.BufferedWriter; import java.io.FileOutputStream; import java.io.IOException; +import org.apache.log4j.helpers.OptionConverter; // Contibutors: Jens Uwe Pipka <[EMAIL PROTECTED]> @@ -122,7 +123,7 @@ // Trim spaces from both ends. The users probably does not want // trailing spaces in file names. String val = file.trim(); - fileName = val; + fileName = OptionConverter.stripDuplicateBackslashes(val); } /** 1.36 +3 -3 logging-log4j/src/java/org/apache/log4j/PatternLayout.java Index: PatternLayout.java =================================================================== RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/PatternLayout.java,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- PatternLayout.java 4 Jan 2005 19:42:10 -0000 1.35 +++ PatternLayout.java 11 Feb 2005 18:11:44 -0000 1.36 @@ -1,5 +1,5 @@ /* - * Copyright 1999,2004 The Apache Software Foundation. + * Copyright 1999-2005 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import org.apache.log4j.pattern.PatternConverter; import org.apache.log4j.pattern.PatternParser; import org.apache.log4j.spi.LoggingEvent; - +import org.apache.log4j.helpers.OptionConverter; // Contributors: Nelson Minar <[EMAIL PROTECTED]> // Anders Kristensen <[EMAIL PROTECTED]> @@ -450,7 +450,7 @@ conversion specifiers. */ public void setConversionPattern(String conversionPattern) { - this.conversionPattern = conversionPattern; + this.conversionPattern = OptionConverter.convertSpecialChars(conversionPattern); } /** 1.52 +22 -0 logging-log4j/src/java/org/apache/log4j/helpers/OptionConverter.java Index: OptionConverter.java =================================================================== RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/helpers/OptionConverter.java,v retrieving revision 1.51 retrieving revision 1.52 diff -u -r1.51 -r1.52 --- OptionConverter.java 13 Jan 2005 16:10:37 -0000 1.51 +++ OptionConverter.java 11 Feb 2005 18:11:44 -0000 1.52 @@ -536,4 +536,26 @@ ((ConfiguratorBase)configurator).dumpErrors(); } } + + /** + * Replaces occurances of double backslashes (if any) in the + * source string with single backslashes. + * @param src source string + * @return source string with double backslashes replaced + */ + public static String stripDuplicateBackslashes(final String src) { + int i = src.lastIndexOf('\\'); + if (i > 0) { + StringBuffer buf = new StringBuffer(src); + for(; i > 0; i = src.lastIndexOf('\\', i - 1)) { + if(src.charAt(i - 1) == '\\') { + buf.deleteCharAt(i); + i--; + if (i == 0) break; + } + } + return buf.toString(); + } + return src; + } } 1.2 +1 -1 logging-log4j/src/java/org/apache/log4j/joran/action/ParamAction.java Index: ParamAction.java =================================================================== RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/joran/action/ParamAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ParamAction.java 12 Jan 2005 15:04:18 -0000 1.1 +++ ParamAction.java 11 Feb 2005 18:11:44 -0000 1.2 @@ -54,7 +54,7 @@ Object o = ec.peekObject(); PropertySetter propSetter = new PropertySetter(o); - value = ec.subst(OptionConverter.convertSpecialChars(value)); + value = ec.subst(value); // allow for variable substitution for name as well name = ec.subst(name); 1.1 logging-log4j/tests/input/xml/DOMTestCase2.xml Index: DOMTestCase2.xml =================================================================== <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration xmlns:log4j='http://logging.apache.org/'> <appender name="A1" class="org.apache.log4j.FileAppender"> <param name="File" value="output\temp.A1.2" /> <param name="Append" value="false" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%-5p %c{2} - %m%n"/> </layout> </appender> <appender name="A2" class="org.apache.log4j.FileAppender"> <param name="File" value="output\temp.A2.2" /> <param name="Append" value="false" /> <layout class="org.apache.log4j.TTCCLayout"> <param name="DateFormat" value="ISO8601" /> </layout> </appender> <!-- Prevent internal log4j DEBUG messages from polluting the output. --> <logger name="org.apache.log4j.joran"><level value="INFO" /></logger> <logger name="org.apache.log4j.joran.action.PriorityAction"><level value="ERROR" /></logger> <logger name="org.apache.log4j.config"><level value="INFO" /></logger> <logger name="org.apache.log4j.FileAppender"><level value="INFO" /></logger> <logger name="org.apache.log4j.xml"> <level value="debug" /> <appender-ref ref="A1" /> </logger> <root> <priority value ="debug" /> <appender-ref ref="A1" /> <appender-ref ref="A2" /> </root> </log4j:configuration> 1.3 +6 -0 logging-log4j/tests/src/java/org/apache/log4j/helpers/OptionSubstitutionTest.java Index: OptionSubstitutionTest.java =================================================================== RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/helpers/OptionSubstitutionTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- OptionSubstitutionTest.java 17 Nov 2004 17:41:49 -0000 1.2 +++ OptionSubstitutionTest.java 11 Feb 2005 18:11:44 -0000 1.3 @@ -127,6 +127,12 @@ assertEquals("HELLO John.", res); } + public void testStripDuplicateBackslashes() { + assertEquals("\\foo\\bar\\foo", OptionConverter.stripDuplicateBackslashes("\\foo\\\\bar\\foo")); + assertEquals("\\foo\\bar\\foo\\", OptionConverter.stripDuplicateBackslashes("\\\\foo\\\\bar\\foo\\")); + assertEquals("\\foo\\bar\\foo\\", OptionConverter.stripDuplicateBackslashes("\\\\foo\\\\bar\\foo\\\\")); +// assertTrue(false); + } public static Test Xsuite() { 1.13 +53 -0 logging-log4j/tests/src/java/org/apache/log4j/xml/DOMTestCase.java Index: DOMTestCase.java =================================================================== RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/xml/DOMTestCase.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- DOMTestCase.java 20 Nov 2004 19:06:58 -0000 1.12 +++ DOMTestCase.java 11 Feb 2005 18:11:44 -0000 1.13 @@ -1,3 +1,18 @@ +/* + * Copyright 1999-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.log4j.xml; @@ -18,6 +33,8 @@ import org.apache.log4j.util.ISO8601Filter; import org.apache.log4j.util.Transformer; import org.apache.log4j.util.Compare; +import org.apache.log4j.FileAppender; +import java.io.File; public class DOMTestCase extends TestCase { @@ -83,6 +100,42 @@ assertTrue(Compare.compare(FILTERED_A2, "witness/xml/dom.A2.1")); } + /** + * Identical test except that backslashes are used instead of + * forward slashes on all file specifications. Test is + * only applicable to Windows. + * + * @throws Exception Any exception will cause test to fail + */ + public void test2() throws Exception { + if (File.separatorChar == '\\') { + JoranConfigurator jc = new JoranConfigurator(); + jc.doConfigure("input\\xml\\DOMTestCase2.xml", LogManager.getLoggerRepository()); + dumpErrors(jc.getErrorList()); + common(); + + ControlFilter cf1 = new ControlFilter(new String[]{TEST1_1A_PAT, TEST1_1B_PAT, + EXCEPTION1, EXCEPTION2, EXCEPTION3}); + + ControlFilter cf2 = new ControlFilter(new String[]{TEST1_2_PAT, + EXCEPTION1, EXCEPTION2, EXCEPTION3}); + + Transformer.transform(TEMP_A1 + ".2", FILTERED_A1 + ".2", new Filter[] {cf1, + new LineNumberFilter(), + new SunReflectFilter(), + new JunitTestRunnerFilter()}); + + Transformer.transform(TEMP_A2 + ".2", FILTERED_A2 + ".2", new Filter[] {cf2, + new LineNumberFilter(), new ISO8601Filter(), + new SunReflectFilter(), new JunitTestRunnerFilter()}); + + assertTrue(Compare.compare(FILTERED_A1, "witness/xml/dom.A1.2")); + assertTrue(Compare.compare(FILTERED_A2, "witness/xml/dom.A2.2")); + } + } + + + void common() { int i = -1; 1.1 logging-log4j/tests/witness/xml/dom.A1.2 Index: dom.A1.2 =================================================================== DEBUG xml.DOMTestCase - Message 0
DEBUG xml.DOMTestCase - Message 0 DEBUG root - Message 0 INFO xml.DOMTestCase - Message 1 INFO xml.DOMTestCase - Message 1 INFO root - Message 1 WARN xml.DOMTestCase - Message 2 WARN xml.DOMTestCase - Message 2 WARN root - Message 2 ERROR xml.DOMTestCase - Message 3 ERROR xml.DOMTestCase - Message 3 ERROR root - Message 3 FATAL xml.DOMTestCase - Message 4 FATAL xml.DOMTestCase - Message 4 FATAL root - Message 4 DEBUG xml.DOMTestCase - Message 5 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(X) at org.apache.log4j.xml.DOMTestCase.test2(X) at java.lang.reflect.Method.invoke(X) at junit.framework.TestCase.runTest(X) at junit.framework.TestCase.runBare(X) at junit.framework.TestResult$1.protect(X) at junit.framework.TestResult.runProtected(X) at junit.framework.TestResult.run(X) at junit.framework.TestCase.run(X) at junit.framework.TestSuite.runTest(X) at junit.framework.TestSuite.run(X) DEBUG xml.DOMTestCase - Message 5 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(X) at org.apache.log4j.xml.DOMTestCase.test2(X) at java.lang.reflect.Method.invoke(X) at junit.framework.TestCase.runTest(X) at junit.framework.TestCase.runBare(X) at junit.framework.TestResult$1.protect(X) at junit.framework.TestResult.runProtected(X) at junit.framework.TestResult.run(X) at junit.framework.TestCase.run(X) at junit.framework.TestSuite.runTest(X) at junit.framework.TestSuite.run(X) DEBUG root - Message 5 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(X) at org.apache.log4j.xml.DOMTestCase.test2(X) at java.lang.reflect.Method.invoke(X) at junit.framework.TestCase.runTest(X) at junit.framework.TestCase.runBare(X) at junit.framework.TestResult$1.protect(X) at junit.framework.TestResult.runProtected(X) at junit.framework.TestResult.run(X) at junit.framework.TestCase.run(X) at junit.framework.TestSuite.runTest(X) at junit.framework.TestSuite.run(X) ERROR xml.DOMTestCase - Message 6 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(X) at org.apache.log4j.xml.DOMTestCase.test2(X) at java.lang.reflect.Method.invoke(X) at junit.framework.TestCase.runTest(X) at junit.framework.TestCase.runBare(X) at junit.framework.TestResult$1.protect(X) at junit.framework.TestResult.runProtected(X) at junit.framework.TestResult.run(X) at junit.framework.TestCase.run(X) at junit.framework.TestSuite.runTest(X) at junit.framework.TestSuite.run(X) ERROR xml.DOMTestCase - Message 6 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(X) at org.apache.log4j.xml.DOMTestCase.test2(X) at java.lang.reflect.Method.invoke(X) at junit.framework.TestCase.runTest(X) at junit.framework.TestCase.runBare(X) at junit.framework.TestResult$1.protect(X) at junit.framework.TestResult.runProtected(X) at junit.framework.TestResult.run(X) at junit.framework.TestCase.run(X) at junit.framework.TestSuite.runTest(X) at junit.framework.TestSuite.run(X) ERROR root - Message 6 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(X) at org.apache.log4j.xml.DOMTestCase.test2(X) at java.lang.reflect.Method.invoke(X) at junit.framework.TestCase.runTest(X) at junit.framework.TestCase.runBare(X) at junit.framework.TestResult$1.protect(X) at junit.framework.TestResult.runProtected(X) at junit.framework.TestResult.run(X) at junit.framework.TestCase.run(X) at junit.framework.TestSuite.runTest(X) at junit.framework.TestSuite.run(X) 1.1 logging-log4j/tests/witness/xml/dom.A2.2 Index: dom.A2.2 =================================================================== [main] DEBUG org.apache.log4j.xml.DOMTestCase - Message 0 [main] DEBUG root - Message 0 [main] INFO org.apache.log4j.xml.DOMTestCase - Message 1 [main] INFO root - Message 1 [main] WARN org.apache.log4j.xml.DOMTestCase - Message 2 [main] WARN root - Message 2 [main] ERROR org.apache.log4j.xml.DOMTestCase - Message 3 [main] ERROR root - Message 3 [main] FATAL org.apache.log4j.xml.DOMTestCase - Message 4 [main] FATAL root - Message 4 [main] DEBUG org.apache.log4j.xml.DOMTestCase - Message 5 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(X) at org.apache.log4j.xml.DOMTestCase.test2(X) at java.lang.reflect.Method.invoke(X) at junit.framework.TestCase.runTest(X) at junit.framework.TestCase.runBare(X) at junit.framework.TestResult$1.protect(X) at junit.framework.TestResult.runProtected(X) at junit.framework.TestResult.run(X) at junit.framework.TestCase.run(X) at junit.framework.TestSuite.runTest(X) at junit.framework.TestSuite.run(X) [main] DEBUG root - Message 5 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(X) at org.apache.log4j.xml.DOMTestCase.test2(X) at java.lang.reflect.Method.invoke(X) at junit.framework.TestCase.runTest(X) at junit.framework.TestCase.runBare(X) at junit.framework.TestResult$1.protect(X) at junit.framework.TestResult.runProtected(X) at junit.framework.TestResult.run(X) at junit.framework.TestCase.run(X) at junit.framework.TestSuite.runTest(X) at junit.framework.TestSuite.run(X) [main] ERROR org.apache.log4j.xml.DOMTestCase - Message 6 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(X) at org.apache.log4j.xml.DOMTestCase.test2(X) at java.lang.reflect.Method.invoke(X) at junit.framework.TestCase.runTest(X) at junit.framework.TestCase.runBare(X) at junit.framework.TestResult$1.protect(X) at junit.framework.TestResult.runProtected(X) at junit.framework.TestResult.run(X) at junit.framework.TestCase.run(X) at junit.framework.TestSuite.runTest(X) at junit.framework.TestSuite.run(X) [main] ERROR root - Message 6 java.lang.Exception: Just testing at org.apache.log4j.xml.DOMTestCase.common(X) at org.apache.log4j.xml.DOMTestCase.test2(X) at java.lang.reflect.Method.invoke(X) at junit.framework.TestCase.runTest(X) at junit.framework.TestCase.runBare(X) at junit.framework.TestResult$1.protect(X) at junit.framework.TestResult.runProtected(X) at junit.framework.TestResult.run(X) at junit.framework.TestCase.run(X) at junit.framework.TestSuite.runTest(X) at junit.framework.TestSuite.run(X) --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]