Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-1818

JavascriptUtils.encodeString does not properly translate '\' characters into "\\" (2) characters

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1.5, 1.2.2
    • 1.1.6
    • General
    • None
    • Standard

    Description

      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;
      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(); }

      }

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            lu4242 Leonardo Uribe
            nicholas.hagen@zidnet.net Nicholas Hagen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment