cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1186897 - in /cxf/branches/2.4.x-fixes: ./ tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java
Date Thu, 20 Oct 2011 16:32:09 GMT
Author: dkulp
Date: Thu Oct 20 16:32:08 2011
New Revision: 1186897

URL: http://svn.apache.org/viewvc?rev=1186897&view=rev
Log:
Merged revisions 1186866 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1186866 | dkulp | 2011-10-20 11:52:52 -0400 (Thu, 20 Oct 2011) | 1 line
  
  [CXF-3855] Fix issue with uri escaping/encoding
........

Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java
    cxf/branches/2.4.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java

Propchange: cxf/branches/2.4.x-fixes/
            ('svn:mergeinfo' removed)

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.4.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java?rev=1186897&r1=1186896&r2=1186897&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java
(original)
+++ cxf/branches/2.4.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java
Thu Oct 20 16:32:08 2011
@@ -227,24 +227,25 @@ public final class URIParserUtil {
     }
 
     public static String escapeChars(String s) {
-        StringBuilder b = new StringBuilder(s);
-        int x = 0;
-        do {
-            char ch = b.charAt(x);
+        StringBuilder b = new StringBuilder(s.length());
+        
+        for (int x = 0; x < s.length(); x++) {
+            char ch = s.charAt(x);
             if (isExcluded(ch)) {
                 try {
                     byte[] bytes = Character.toString(ch).getBytes("UTF-8");
-                    b.setCharAt(x++, '%');
                     for (int y = 0; y < bytes.length; y++) {
-                        b.insert(x++, HEX_DIGITS.charAt((bytes[y] & 0xFF) >> 4));
-                        b.insert(x, HEX_DIGITS.charAt(bytes[y] & 0x0F));
+                        b.append("%");
+                        b.append(HEX_DIGITS.charAt((bytes[y] & 0xFF) >> 4));
+                        b.append(HEX_DIGITS.charAt(bytes[y] & 0x0F));
                     }
                 } catch (UnsupportedEncodingException e) {
                     //should not happen
                 }
+            } else {
+                b.append(ch);
             }
-            x++;
-        } while (x < b.length());
+        }
         return b.toString();
     }
     public static String normalize(final String uri) {

Modified: cxf/branches/2.4.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java?rev=1186897&r1=1186896&r2=1186897&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java
(original)
+++ cxf/branches/2.4.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java
Thu Oct 20 16:32:08 2011
@@ -19,6 +19,9 @@
 
 package org.apache.cxf.tools.util;
 
+import java.io.File;
+import java.net.URI;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -93,4 +96,11 @@ public class URIParserUtilTest extends A
         uri = "file:/home/john/test/all/../../alltest";
         assertEquals("file:/home/john/alltest", URIParserUtil.getAbsoluteURI(uri));
     }
+    @Test
+    public void testCXF3855() throws Exception {
+        String orig = new String(new byte[] {-47, -122}, "UTF-8");
+        orig = "/foo" + orig + ".txt";
+        String s = URIParserUtil.escapeChars(orig);
+        assertEquals(orig, new File(new URI("file:" + s)).getAbsolutePath());
+    }
 }



Mime
View raw message