JIRA

  • Log In Access more options
    • Online Help
    • GreenHopper Help
    • Agile Answers
    • Use Agile By Default
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Agile Access more options (Alt+g)
  • Create Issue
  • Mule
  • MULE-5853

#[map-payload:key1,key2?] does not evaluate correctly

  • Agile Board
  • More Actions
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 3.2.0
  • Fix Version/s: 3.1.4 (EE only), 3.2.2 (EE only)
  • Component/s: Core: Expressions
  • Labels:
    None
  • User impact:
    Medium
  • Similar Issues:
    None

Description

The result of #[map-payload:key1,key2?] is the expression itself, since the "?" is not escaped when doing regular expression replace in the TemplateParser. This probably affects other situations when optional parameters with "?" are used.

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    MapPayloadExpressionEvaluatorTestCase.patch
    31/Oct/11 11:12 PM
    2 kB
    Dirk Olmes

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
  • Transitions
  • Commits
  • Source
  • Builds
Hide
Permalink
Ivan Krizsan added a comment - 26/Oct/11 02:21 PM

The following test case added to the org.mule.util.TemplateParserTestCase tests for the bug:
/**

  • Tests replacing properties with question mark in the name.
  • This can occur, for instance, when retrieving optional
  • keys from a map using the map-payload evaluator.
    */
    @Test
    public void testStringParserQuestionMarkInPropertyName()
    {
    TemplateParser tp = TemplateParser.createAntStyleParser();
    Map props = new HashMap();
    props.put("prop1?", "value1");
    props.put("prop1-2", "value2");
    String string = "Some String with ${prop1?} and ${prop1-2} in it";

String result = tp.parse(props, string);
assertEquals("Some String with value1 and value2 in it", result);
}

Show
Ivan Krizsan added a comment - 26/Oct/11 02:21 PM The following test case added to the org.mule.util.TemplateParserTestCase tests for the bug: /**
  • Tests replacing properties with question mark in the name.
  • This can occur, for instance, when retrieving optional
  • keys from a map using the map-payload evaluator. */ @Test public void testStringParserQuestionMarkInPropertyName() { TemplateParser tp = TemplateParser.createAntStyleParser(); Map props = new HashMap(); props.put("prop1?", "value1"); props.put("prop1-2", "value2"); String string = "Some String with ${prop1?} and ${prop1-2} in it";
String result = tp.parse(props, string); assertEquals("Some String with value1 and value2 in it", result); }
Hide
Permalink
Ivan Krizsan added a comment - 26/Oct/11 02:24 PM

Modifying (added case '?': in the switch) the following method in the org.mule.util.TemplateParser makes the above test case pass. I have not tested whether other components/test are affected.

private String escape(String string)
{
int length = string.length();
if (length == 0)

{ // nothing to do return string; }

else
{
StringBuffer buffer = new StringBuffer(length * 2);
for (int i = 0; i < length; i++)
{
char currentCharacter = string.charAt;
switch (currentCharacter)
{
case '[':
case ']':
case '{': case '}':
case '(':
case ')':
case '$':
case '#':
case '*':
case '?':
buffer.append("
");
// $FALL-THROUGH$ fall through to append original character
default:
buffer.append(currentCharacter);
}
}
return buffer.toString();
}
}

Show
Ivan Krizsan added a comment - 26/Oct/11 02:24 PM Modifying (added case '?': in the switch) the following method in the org.mule.util.TemplateParser makes the above test case pass. I have not tested whether other components/test are affected. private String escape(String string) { int length = string.length(); if (length == 0) { // nothing to do return string; } else { StringBuffer buffer = new StringBuffer(length * 2); for (int i = 0; i < length; i++) { char currentCharacter = string.charAt; switch (currentCharacter) { case '[': case ']': case '{': case '}': case '(': case ')': case '$': case '#': case '*': case '?': buffer.append("
"); // $FALL-THROUGH$ fall through to append original character default: buffer.append(currentCharacter); } } return buffer.toString(); } }
Hide
Permalink
Dirk Olmes added a comment - 31/Oct/11 11:12 PM

I cannot reproduce the issue described. If you apply MapPayloadExpressionEvaluatorTestCase and run the test, it ignores the optional value as it should.

Can you please post a use case/config that exposes this bug?

Show
Dirk Olmes added a comment - 31/Oct/11 11:12 PM I cannot reproduce the issue described. If you apply MapPayloadExpressionEvaluatorTestCase and run the test, it ignores the optional value as it should. Can you please post a use case/config that exposes this bug?
Hide
Permalink
Ivan Krizsan added a comment - 01/Nov/11 02:07 AM

If I create a message with a map payload as this:
Map<String, String> thePayload = new HashMap<String, String>();
thePayload.put("Key1", "Value1");
MuleMessage theMuleMessage = new DefaultMuleMessage(thePayload, theContext1);
The in my configuration file do this:
<logger level="ERROR" message="***** Keys in the map: #[map-payload:Key1,Key2?]"/>
I get this console output:

          • Keys in the map: #[map-payload:Key1,Key2?]
            With my patch in place, I get this output:
          • Keys in the map: {Key1=Value1}

Hope this suffices. Please let me know if you want a complete example.

Show
Ivan Krizsan added a comment - 01/Nov/11 02:07 AM If I create a message with a map payload as this: Map<String, String> thePayload = new HashMap<String, String>(); thePayload.put("Key1", "Value1"); MuleMessage theMuleMessage = new DefaultMuleMessage(thePayload, theContext1); The in my configuration file do this: <logger level="ERROR" message="***** Keys in the map: #[map-payload:Key1,Key2?]"/> I get this console output:
          • Keys in the map: #[map-payload:Key1,Key2?] With my patch in place, I get this output:
          • Keys in the map: {Key1=Value1}
Hope this suffices. Please let me know if you want a complete example.
Hide
Permalink
Dirk Olmes added a comment - 04/Nov/11 12:42 PM

3.1.x: http://fisheye.codehaus.org/changelog/mule/?cs=23326
3.2.x: http://fisheye.codehaus.org/changelog/mule/?cs=23328
3.x: http://fisheye.codehaus.org/changelog/mule/?cs=23329

Show
Dirk Olmes added a comment - 04/Nov/11 12:42 PM 3.1.x: http://fisheye.codehaus.org/changelog/mule/?cs=23326 3.2.x: http://fisheye.codehaus.org/changelog/mule/?cs=23328 3.x: http://fisheye.codehaus.org/changelog/mule/?cs=23329
Hide
Permalink
Pablo Kraan added a comment - 08/Jun/12 07:49 AM

Reopening to assign correct fix versions

Show
Pablo Kraan added a comment - 08/Jun/12 07:49 AM Reopening to assign correct fix versions

People

  • Assignee:
    Dirk Olmes
    Reporter:
    Ivan Krizsan
Vote (1)
Watch (1)

Dates

  • Created:
    26/Oct/11 02:19 PM
    Updated:
    08/Jun/12 07:50 AM
    Resolved:
    08/Jun/12 07:50 AM

Agile

  • View on Board
  • Atlassian JIRA (v5.0.7#734-sha1:8ad78a6)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for MuleForge. Try JIRA - bug tracking software for your team.