Author: toad
Date: 2007-08-14 14:05:21 +0000 (Tue, 14 Aug 2007)
New Revision: 14684

Modified:
   trunk/freenet/src/freenet/support/URLDecoder.java
Log:
Was broken for non-ASCII chars with pureASCII=false.
sback please put a test in for this.

Modified: trunk/freenet/src/freenet/support/URLDecoder.java
===================================================================
--- trunk/freenet/src/freenet/support/URLDecoder.java   2007-08-14 04:27:37 UTC 
(rev 14683)
+++ trunk/freenet/src/freenet/support/URLDecoder.java   2007-08-14 14:05:21 UTC 
(rev 14684)
@@ -5,6 +5,7 @@

 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;

 /**
@@ -41,7 +42,7 @@
                if (s.length() == 0)
                        return "";
                int len = s.length();
-               ByteArrayOutputStream decodedBytes = new 
ByteArrayOutputStream();
+               StringWriter decodedBytes = new StringWriter();
                boolean hasDecodedSomething = false;

                for (int i = 0; i < len; i++) {
@@ -67,29 +68,20 @@
                                } catch (NumberFormatException nfe) {
                                        // Not encoded?
                                        if(tolerant && !hasDecodedSomething) {
-                                               try {
-                                                       byte[] buf = 
('%'+hexval).getBytes("UTF-8");
-                                                       decodedBytes.write(buf, 
0, buf.length);
-                                                       continue;
-                                               } catch 
(UnsupportedEncodingException e) {
-                                                       throw new Error(e);
-                                               }
+                                               decodedBytes.write('%');
+                                               decodedBytes.write(hexval);
+                                               continue;
                                        }

                                        throw new 
URLEncodedFormatException("Not a two character hex % escape: "+hexval+" in "+s);
                                }
                        } else {
-                               try {
-                                       byte[] encoded = 
(""+c).getBytes("UTF-8");
-                                       decodedBytes.write(encoded, 0, 
encoded.length);
-                               } catch (UnsupportedEncodingException e) {
-                                       throw new Error(e);
-                               }
+                               decodedBytes.write(c);
                        }
                }
                try {
                        decodedBytes.close();
-                       return new String(decodedBytes.toByteArray(), "utf-8");
+                       return decodedBytes.toString();
                } catch (IOException ioe1) {
                        /* if this throws something's wrong */
                }


Reply via email to