myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r544552 - /myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/ParameterResourceHandler.java
Date Tue, 05 Jun 2007 16:56:28 GMT
Author: imario
Date: Tue Jun  5 09:56:27 2007
New Revision: 544552

URL: http://svn.apache.org/viewvc?view=rev&rev=544552
Log:
TOMAHAWK-1016: encode the url parameter to correctly deal with "#", " " etc characters

Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/ParameterResourceHandler.java

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/ParameterResourceHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/ParameterResourceHandler.java?view=diff&rev=544552&r1=544551&r2=544552
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/ParameterResourceHandler.java
(original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/component/html/util/ParameterResourceHandler.java
Tue Jun  5 09:56:27 2007
@@ -18,15 +18,17 @@
  */
 package org.apache.myfaces.component.html.util;
 
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.faces.context.FacesContext;
-
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.myfaces.renderkit.html.util.ResourceHandler;
 
+import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Iterator;
+import java.util.Map;
+
 /**
  * @author Mathias Broekelmann
  *
@@ -70,8 +72,26 @@
                 Map.Entry entry = (Map.Entry) iter.next();
                 sb.append(entry.getKey());
                 sb.append("=");
-                sb.append(entry.getValue());
-                if (iter.hasNext())
+				if (entry.getValue() != null)
+				{
+					try
+					{
+						// encode the value to make it safe to be passed through the url
+						// the best we can do here is to use the same encoding than the response writer
+						String encoding = context.getResponseWriter().getCharacterEncoding();
+						if (encoding == null)
+						{
+							// or fallback to UTF-8 (which makes the most sense)
+							encoding = "UTF-8";
+						}
+						sb.append(URLEncoder.encode(entry.getValue().toString(), encoding));
+					}
+					catch (UnsupportedEncodingException e)
+					{
+						throw new FacesException(e.getLocalizedMessage(), e);
+					}
+				}
+				if (iter.hasNext())
                 {
                     sb.append("&");
                 }



Mime
View raw message