carnold     2005/02/11 13:17:11

  Modified:    src/java/org/apache/log4j/helpers OptionConverter.java
               tests/src/java/org/apache/log4j/helpers
                        OptionSubstitutionTest.java
  Log:
  bug 22894: Backslashes in file specs, UNC handling
  
  Revision  Changes    Path
  1.53      +21 -2     
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.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- OptionConverter.java      11 Feb 2005 18:11:44 -0000      1.52
  +++ OptionConverter.java      11 Feb 2005 21:17:11 -0000      1.53
  @@ -33,10 +33,12 @@
   // Contributors:   Avy Sharell 
   //                 Matthieu Verbert
   //                 Colin Sampaleanu
  +//                 Curt Arnold
   
   // Contributors:   Avy Sharell 
   //                 Matthieu Verbert
   //                 Colin Sampaleanu
  +//                 Curt Arnold
   
   /**
    * A convenience class to convert property values to specific types.
  @@ -45,6 +47,7 @@
    * @author Simon Kitching;
    * @author Anders Kristensen
    * @author Avy Sharell
  + * @author Curt Arnold
   */
   public class OptionConverter  {
     static String DELIM_START = "${";
  @@ -538,20 +541,36 @@
     }
     
     /**
  -   * Replaces occurances of double backslashes (if any) in the
  -   * source string with single backslashes.
  +   * Replaces double backslashes (except the leading doubles in UNC's)
  +   * with single backslashes for compatibility with existing path 
specifications
  +   * that were working around use of OptionConverter.convertSpecialChars
  +   * in XML configuration files.
  +   * 
      * @param src source string
      * @return source string with double backslashes replaced
  +   * 
  +   * @since 1.3
      */
     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 the preceding character is a slash then
  +                     //     remove the preceding character
  +                     //     and continue processing with the earlier part of 
the string
                        if(src.charAt(i - 1) == '\\') {
                                buf.deleteCharAt(i);
                                i--;
                                if (i == 0) break;
  +                     } else {
  +                             //
  +                             //  if there was a single slash then
  +                             //    the string was not trying to work around
  +                             //    convertSpecialChars
  +                             //
  +                             return src;
                        }
                }
                return buf.toString();
  
  
  
  1.4       +22 -4     
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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- OptionSubstitutionTest.java       11 Feb 2005 18:11:44 -0000      1.3
  +++ OptionSubstitutionTest.java       11 Feb 2005 21:17:11 -0000      1.4
  @@ -10,6 +10,7 @@
    * Test variable substitution code in OptionConverter.substVars method.
    * 
    * @author Ceki Gülcü
  + * @author Curt Arnold
    * 
    * @since 1.0
    */
  @@ -127,11 +128,28 @@
       assertEquals("HELLO John.", res);
     }
     
  +  /**
  +   * Tests OptionsConverter.stripDuplicateBackslashes
  +   *
  +   * @since 1.3
  +   */
     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);
  +     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\\"));
  +     //
  +     //   UNC's should either start with two backslashes and contain 
additional singles
  +     //       or four back slashes and addition doubles
  +     assertEquals("\\\\foo\\bar\\foo", 
OptionConverter.stripDuplicateBackslashes("\\\\\\\\foo\\\\bar\\\\foo"));
  +     assertEquals("\\\\foo\\bar\\foo", 
OptionConverter.stripDuplicateBackslashes("\\\\foo\\bar\\foo"));
  +      //
  +      //   it it starts with doubles but has no other path component
  +      //      then it is a file path
  +     assertEquals("\\foo.log", 
OptionConverter.stripDuplicateBackslashes("\\\\foo.log"));
  +      //
  +      //   it it starts with quads but has no other path component
  +      //      then it is a UNC
  +     assertEquals("\\\\foo.log", 
OptionConverter.stripDuplicateBackslashes("\\\\\\\\foo.log"));
     }  
     
     
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to