Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-3529

NamedVariablePatternMatcher does not properly escape characters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.1
    • 6.1.1
    • Other
    • None
    • Patch

    Description

      The com.opensymphony.xwork2.util.NamedVariablePatternMatcher class has a bug in the compilePattern(String) method. The purpose of the method is to compile patterns such as "action/{foo}" to a regular expression Pattern and extract the variable names that match each group in the regex. In the example given and the 2.2.1 code base, the pattern will be compiled as "action/([^/]+)". However, if the pattern includes characters that have special meaning to Java's regular expression engine, they are currently not being escaped.

      For example, the pattern "action.{format}" is being compiled to "action.([^/])" which correctly matches "action.html" but also "actionK.html" or any other character because the '.' is not escaped. The bug really bites when a pattern like "{name}.{format}" is used. This will be compiled to "([^/]).([^/]+)" which will match "cars.html" but not the way you expect. Because of greediness, it will set name = "cars.ht" and format = "l".

      I will submit a patch to fix this behavior on the next screen.

      Attachments

        1. NamedVariablePatternMatcher.patch
          3 kB
          Richard Vermillion

        Issue Links

          Activity

            People

              Unassigned Unassigned
              rvermillion Richard Vermillion
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h