[ 
https://issues.apache.org/jira/browse/MYFACES-1818?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12620787#action_12620787
 ] 

Nicholas Hagen commented on MYFACES-1818:
-----------------------------------------

if I understand the point of the method and the way we have used in our env, it 
is to take a string like a user quoted string and encode it into a valid 
javascript encoded string. Thus if the component wanted to encode the string

Test 1 \ 5

It would return "Test 1 \ 5" which would fail in javascript because that is 
invalid escape sequence. With my fix it would be "Test 1 \\ 5" which would be a 
valid quoted string and as such render to the page as 1 \ 5.  

> JavascriptUtils.encodeString does not properly translate '\' characters into 
> "\\" (2) characters
> ------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-1818
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1818
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General
>    Affects Versions: 1.1.5, 1.2.2
>         Environment: Standard
>            Reporter: Nicholas Hagen
>   Original Estimate: 0h
>  Remaining Estimate: 0h
>
> JavascriptUtils.encodeString does not properly translate a single '\' 
> backslash char into two "\\" backslash characters in order to properly escape 
> the Javascript string.  The fix should be:
> public static String encodeString(String string)
>     {
>         if (string == null)
>         {
>             return "";
>         }
>         StringBuffer sb = null;       //create later on demand
>         String app;
>         char c;
>         for (int i = 0; i < string.length (); ++i)
>         {
>             app = null;
>             c = string.charAt(i);
>             switch (c)
>             {
>                 case '\\' : app = "\\\\";  break; // NJH - Use double 
> backslash as output for single backslash rather than  single backslash for 
> single backslash
>                 case '"' : app = "\\\"";  break;
>                 case '\'' : app = "\\'";  break;
>                 case '\n' : app = "\\n";  break;
>                 case '\r' : app = "\\r";  break;
>             }
>             if (app != null)
>             {
>                 if (sb == null)
>                 {
>                     sb = new StringBuffer(string.substring(0, i));
>                 }
>                 sb.append(app);
>             } else {
>                 if (sb != null)
>                 {
>                     sb.append(c);
>                 }
>             }
>         }
>         if (sb == null)
>         {
>             return string;
>         }
>         else
>         {
>             return sb.toString();
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to