src/share/classes/com/sun/jndi/toolkit/url/UrlUtil.java
Print this page
rev 5095 : 6961765: Double byte characters corrupted in DN for LDAP referrals
@@ -25,10 +25,11 @@
package com.sun.jndi.toolkit.url;
import java.net.MalformedURLException;
import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
/**
* Utilities for dealing with URLs.
* @author Vincent Ryan
*/
@@ -60,34 +61,19 @@
*
* The string is subsequently converted using the specified encoding
*/
public static final String decode(String s, String enc)
throws MalformedURLException, UnsupportedEncodingException {
-
- int length = s.length();
- byte[] bytes = new byte[length];
- int j = 0;
-
- for (int i = 0; i < length; i++) {
- if (s.charAt(i) == '%') {
- i++; // skip %
try {
- bytes[j++] = (byte)
- Integer.parseInt(s.substring(i, i + 2), 16);
-
- } catch (Exception e) {
- throw new MalformedURLException("Invalid URI encoding: " + s);
- }
- i++; // skip first hex char; for loop will skip second one
- } else {
- bytes[j++] = (byte) s.charAt(i);
+ return URLDecoder.decode(s, enc);
+ } catch (IllegalArgumentException iae) {
+ MalformedURLException mue = new MalformedURLException("Invalid URI encoding: " + s);
+ mue.initCause(iae);
+ throw mue;
}
}
- return new String(bytes, 0, j, enc);
- }
-
/**
* Encode a string for inclusion in a URI (according to RFC 2396).
*
* Unsafe characters are escaped by encoding them in three-character
* sequences '%xy', where 'xy' is the two-digit hexadecimal representation