myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sobr...@apache.org
Subject svn commit: r1622814 - /myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/URLUtils.java
Date Fri, 05 Sep 2014 22:39:41 GMT
Author: sobryan
Date: Fri Sep  5 22:39:40 2014
New Revision: 1622814

URL: http://svn.apache.org/r1622814
Log:
TRINIDAD-2441 - URLUtil to escape a URL and remove invalid characters

* Changed encoding to use \x notation for javascript strings rather then %HH URL encoding

Modified:
    myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/URLUtils.java

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/URLUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/URLUtils.java?rev=1622814&r1=1622813&r2=1622814&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/URLUtils.java
(original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java/org/apache/myfaces/trinidad/util/URLUtils.java
Fri Sep  5 22:39:40 2014
@@ -103,10 +103,9 @@ public final class URLUtils
   }
   
   /**
-   * Takes a URL that is not escaped and simply removes any invalid characters, replacing
them with thier %XX
-   * equivalents.
+   * Takes a URL that is not escaped for javascript and escapes it   
    */
-  public static String escapeURL(String url, String charset)
+  public static String jsEncodeURL(String url, String charset)
     throws UnsupportedEncodingException
   {
     StringBuilder sb = new StringBuilder(url.length() * 2);
@@ -115,8 +114,7 @@ public final class URLUtils
       if ((c >= 'A' && c <= 'Z') ||
             (c >= 'a' && c <= 'z') ||
             (c >= '0' && c <= '9') ||
-            (c == _URL_ENCODE_CHARACTER) ||
-            _URL_VALID_CHARS.indexOf(c) > -1
+            _JS_IMMUNE_CHARS.indexOf(c) > -1
          )
       {
         //Valid character.  Just append.
@@ -127,7 +125,7 @@ public final class URLUtils
         //This is an invalid character, so we encode need to get the bytes
         for(byte b: Character.toString(c).getBytes(charset))
         {
-          sb.append("%")
+          sb.append("\\x")
             .append(String.format("%02X", b));
         }
       }
@@ -258,6 +256,5 @@ public final class URLUtils
   private static final String _URL_QUERY_SEPERATOR="?";
   private static final String _URL_FRAGMENT_SEPERATOR="#";
   private static final String _URL_NAME_VALUE_PAIR_SEPERATOR="=";
-  private static final char _URL_ENCODE_CHARACTER='%';
-  private static final String _URL_VALID_CHARS="-._~://?#[]@!$&'()*+,;=";
-}
\ No newline at end of file
+  private static final String _JS_IMMUNE_CHARS=",._";
+}



Mime
View raw message