Author: dkulp Date: Thu Oct 20 16:45:29 2011 New Revision: 1186911 URL: http://svn.apache.org/viewvc?rev=1186911&view=rev Log: Merged revisions 1186897 via svnmerge from https://svn.us.apache.org/repos/asf/cxf/branches/2.4.x-fixes
................ r1186897 | dkulp | 2011-10-20 12:32:08 -0400 (Thu, 20 Oct 2011) | 9 lines 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.3.x-fixes/ (props changed) cxf/branches/2.3.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java cxf/branches/2.3.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java Propchange: cxf/branches/2.3.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.3.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java?rev=1186911&r1=1186910&r2=1186911&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java (original) +++ cxf/branches/2.3.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java Thu Oct 20 16:45:29 2011 @@ -226,24 +226,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.3.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java?rev=1186911&r1=1186910&r2=1186911&view=diff ============================================================================== --- cxf/branches/2.3.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java (original) +++ cxf/branches/2.3.x-fixes/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java Thu Oct 20 16:45:29 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; @@ -90,4 +93,11 @@ public class URIParserUtilTest extends A uri = "http://hello/world.wsdl"; assertEquals(uri, 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()); + } }
