You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2006/04/07 16:35:21 UTC

svn commit: r392306 - /xerces/java/trunk/tests/xinclude/Test.java

Author: peterjm
Date: Fri Apr  7 07:35:19 2006
New Revision: 392306

URL: http://svn.apache.org/viewcvs?rev=392306&view=rev
Log:
Fixing a bug where Test 24 failed when there are spaces in the path to the user directory.

Modified:
    xerces/java/trunk/tests/xinclude/Test.java

Modified: xerces/java/trunk/tests/xinclude/Test.java
URL: http://svn.apache.org/viewcvs/xerces/java/trunk/tests/xinclude/Test.java?rev=392306&r1=392305&r2=392306&view=diff
==============================================================================
--- xerces/java/trunk/tests/xinclude/Test.java (original)
+++ xerces/java/trunk/tests/xinclude/Test.java Fri Apr  7 07:35:19 2006
@@ -1,5 +1,5 @@
 /*
- * Copyright 2003,2004 The Apache Software Foundation.
+ * Copyright 2003,2004,2006 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.
@@ -27,6 +27,7 @@
 import java.io.Reader;
 import java.io.StringReader;
 import java.io.StringWriter;
+import java.util.StringTokenizer;
 
 import org.apache.xerces.parsers.XIncludeParserConfiguration;
 import org.apache.xerces.xni.XNIException;
@@ -307,8 +308,8 @@
                 }
             }
             else {
-				compareOutput(new FileReader(expectedOutputFile),
-									new StringReader(fResults));
+                compareOutput(new FileReader(expectedOutputFile),
+                                    new StringReader(fResults));
                 fLogStream.println(fResults);
                 fLogStream.println("Result: FAIL");
                 return false;
@@ -450,9 +451,6 @@
         return true;
     }
 
-    // returns "true" if the Strings are different only because of
-    // a different absolute filename (NOTE: only works if they are different because
-    // of ONE filename)
     private String stripUserDir(StringBuffer buf) {
         String userDir = System.getProperty("user.dir");
         String userURI = "file://";
@@ -460,7 +458,7 @@
             userURI += "/";
         }
         userURI += userDir.replace('\\', '/');
-        String str = buf.toString();
+        String str = getPathWithoutEscapes(buf.toString());
 
         int start = 0, end = 0;
         // strip ones in URI form
@@ -476,5 +474,23 @@
             str = str.substring(0, start) + str.substring(end+1);
         }
         return str;
+    }
+    
+    private static String getPathWithoutEscapes(String origPath) {
+        if (origPath != null && origPath.length() != 0 && origPath.indexOf('%') != -1) {
+            // Locate the escape characters
+            StringTokenizer tokenizer = new StringTokenizer(origPath, "%");
+            StringBuffer result = new StringBuffer(origPath.length());
+            int size = tokenizer.countTokens();
+            result.append(tokenizer.nextToken());
+            for(int i = 1; i < size; ++i) {
+                String token = tokenizer.nextToken();
+                // Decode the 2 digit hexadecimal number following % in '%nn'
+                result.append((char)Integer.valueOf(token.substring(0, 2), 16).intValue());
+                result.append(token.substring(2));
+            }
+            return result.toString();
+        }
+        return origPath;
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org