You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2010/02/04 17:20:30 UTC
svn commit: r906550 - in /cxf/branches/2.2.x-fixes: ./
tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java
Author: dkulp
Date: Thu Feb 4 16:20:29 2010
New Revision: 906550
URL: http://svn.apache.org/viewvc?rev=906550&view=rev
Log:
Merged revisions 906546 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r906546 | dkulp | 2010-02-04 11:15:41 -0500 (Thu, 04 Feb 2010) | 1 line
[CXF-2647] Add a better escaping algorithm for the URI's.
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.2.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java?rev=906550&r1=906549&r2=906550&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java (original)
+++ cxf/branches/2.2.x-fixes/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java Thu Feb 4 16:20:29 2010
@@ -20,6 +20,7 @@
package org.apache.cxf.tools.util;
import java.io.File;
+import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
@@ -41,11 +42,17 @@
"public", "return", "short", "static", "strictfp", "super", "switch",
"synchronized", "this", "throw", "throws", "transient", "try", "void",
"volatile", "while", "true", "false", "null", "assert", "enum"}));
+ private static final String EXCLUDED_CHARS = "<>\"{}|\\^`";
+ private static final String HEX_DIGITS = "0123456789abcdef";
private URIParserUtil() {
// complete
}
+ private static boolean isExcluded(char ch) {
+ return ch <= 0x20 || ch >= 0x7F || EXCLUDED_CHARS.indexOf(ch) != -1;
+ }
+
public static URL[] pathToURLs(String path) {
StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
URL[] urls = new URL[st.countTokens()];
@@ -218,11 +225,32 @@
return KEYWORDS.contains(token);
}
+ private static String escapeChars(String s) {
+ StringBuilder b = new StringBuilder(s);
+ int x = 0;
+ do {
+ char ch = b.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));
+ }
+ } catch (UnsupportedEncodingException e) {
+ //should not happen
+ }
+ }
+ x++;
+ } while (x < b.length());
+ return b.toString();
+ }
public static String normalize(final String uri) {
URL url = null;
try {
url = new URL(uri);
- return url.toString().replace("\\", "/");
+ return escapeChars(url.toString().replace("\\", "/"));
} catch (MalformedURLException e1) {
try {
if (uri.startsWith("classpath:")) {
@@ -244,9 +272,9 @@
f = "file:" + uri;
}
url = new URL(f);
- return url.toString().replace("\\", "/");
+ return escapeChars(url.toString().replace("\\", "/"));
} catch (Exception e2) {
- return uri.replace("\\", "/");
+ return escapeChars(uri.replace("\\", "/"));
}
}
}