incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r698147 - /incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/Util.java
Date Tue, 23 Sep 2008 11:49:34 GMT
Author: fmeschbe
Date: Tue Sep 23 04:49:34 2008
New Revision: 698147

URL: http://svn.apache.org/viewvc?rev=698147&view=rev
Log:
SLING-672 Correctly Re-Encode parameter names not using the URLDecoder

Modified:
    incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/Util.java

Modified: incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/Util.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/Util.java?rev=698147&r1=698146&r2=698147&view=diff
==============================================================================
--- incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/Util.java
(original)
+++ incubator/sling/trunk/engine/src/main/java/org/apache/sling/engine/impl/parameters/Util.java
Tue Sep 23 04:49:34 2008
@@ -21,7 +21,6 @@
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -112,15 +111,12 @@
                         param.setEncoding(formEncoding);
 
                         // prepare the parameter for renaming
-                        try {
-                            if (parName == null) {
-                                parName = paramEntry.getKey();
-                                String name = URLDecoder.decode(parName,
-                                    formEncoding);
-                                renameMap.put(paramEntry.getKey(), name);
+                        if (parName == null) {
+                            parName = paramEntry.getKey();
+                            String name = reencode(parName, formEncoding);
+                            if (!parName.equals(name)) {
+                                renameMap.put(parName, name);
                             }
-                        } catch (UnsupportedEncodingException uee) {
-                            // unexpected, as the encoding has been checked !
                         }
                     }
                 }
@@ -134,4 +130,18 @@
             }
         }
     }
+
+    private static String reencode(String parName, String encoding) {
+        // re-encode the parameter to the encoding
+        if (!ENCODING_DIRECT.equals(encoding)) {
+            try {
+                return new String(parName.getBytes(ENCODING_DIRECT), encoding);
+            } catch (UnsupportedEncodingException uee) {
+                // unexpected, as the encoding is assumed to have been checked !
+            }
+        }
+
+        // otherwise just return the name unmodified
+        return parName;
+    }
 }



Mime
View raw message