Uploaded image for project: 'MyFaces Tomahawk'
  1. MyFaces Tomahawk
  2. TOMAHAWK-18

HtmlMessageRenderer's replacement of input ID with input label fails when label is not escaped

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • Message(s)
    • None

    Description

      If you try to use <t:message> with an input component that has a label that is not escaped properly (has a '$' or some other special regex character), the rendering of the message component fails with the following error:

      The following exception is thrown:

      java.lang.IndexOutOfBoundsException: No group 1
      at java.util.regex.Matcher.group(Matcher.java:463)
      at java.util.regex.Matcher.appendReplacement(Matcher.java:730)
      at java.util.regex.Matcher.replaceAll(Matcher.java:806)
      at java.lang.String.replaceAll(String.java:2000)
      at org.apache.myfaces.renderkit.html.ext.HtmlMessageRenderer.getDetail(HtmlMessageRenderer.java:107)
      ...

      This happens when replaceAll() is called in the following places:

      org.apache.myfaces.renderkit.html.ext.HtmlMessageRenderer.getSummary()
      ...
      msgSummary = msgSummary.replaceAll(findInputId(facesContext, msgClientId),inputLabel); (line 72)

      ...

      org.apache.myfaces.renderkit.html.ext.HtmlMessageRenderer.getDetail()
      ...
      msgDetail = msgDetail.replaceAll(findInputId(facesContext, msgClientId),inputLabel); (line 108)

      ...

      If the inputLabel string contains a '$', then it breaks.

      I think the proper fix would be to replace all regex special characters in inputLabel with their escaped sequences right before calling replaceAll(). For example:

      inputLabel = inputLabel.replaceAll("\\\\", "\\\\\\\\").replaceAll("
      $", "\\\\\\$");

      I don't know regex well enough to know what all the special characters are or if there is some method that can be called to do this escaping for us. I'd be happy to submit a patch if someone could help me determine what the proper fix would be. Thanks.

      Attachments

        Activity

          People

            Unassigned Unassigned
            kweiner Ken Weiner
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: