Skip to content

Commit

Permalink
svn merge -c1594481 ^/tiles/framework/branches/TILES_3_0_X .
Browse files Browse the repository at this point in the history
| further fixes on 
|      TILES-574 – Tiles expressions do not work after wildcard
| 
| PatternUtil.INVALID_FORMAT_ELEMENT, the pattern to match "{.*}" occurrances that are not meant to be replaced, was in some cases was matching two much.
|  see test PatternUtilTest.testReplacePlaceholdersEL_options
| This resulted in "PatternSyntaxException: named capturing group is missing trailing }"
| 
| 3 tests have been added to cover such various side-cases.


git-svn-id: https://svn.apache.org/repos/asf/tiles/framework/trunk@1594483 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
michaelsembwever committed May 14, 2014
1 parent 109bc00 commit 951d6a2
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public final class PatternUtil {

/** Pattern to find {.*} occurrences that do not match {[0-9]+} so to prevent MessageFormat from crashing.
*/
private static final Pattern INVALID_FORMAT_ELEMENT = Pattern.compile("\\Q{\\E[\\D^}]+\\Q}\\E");
private static final Pattern INVALID_FORMAT_ELEMENT = Pattern.compile("\\{[^}0-9]+\\}");

/**
* Private constructor to avoid instantiation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,73 @@ public void testReplacePlaceholdersEL_2() {
"some-${requestScope.someVariable}-other-value1-${requestScope.someOtherVariable}.jsp",
nudef.getAttribute("something").getExpressionObject().getExpression());
}

/**
* Test method for
* {@link PatternUtil#replacePlaceholders(Definition, String, Object[])}.
*/
@Test
public void testReplacePlaceholdersEL_conditional() {
Map<String, Attribute> attributes = new HashMap<String, Attribute>();
Attribute attribute = new Attribute("{1}/some-other-{2}-${requestScope.someBoolean ? 'a' : 'b'}.jsp");
attribute.setExpressionObject(new Expression((String)attribute.getValue()));
attributes.put("something", attribute);
Definition definition = new Definition("definitionName", new Attribute("template"), attributes);
Definition nudef = PatternUtil.replacePlaceholders(definition, "nudef", "value0", "value1", "value2", "value3");
assertEquals("nudef", nudef.getName());

assertEquals(
"value1/some-other-value2-${requestScope.someBoolean ? 'a' : 'b'}.jsp",
nudef.getAttribute("something").getValue());

assertEquals(
"value1/some-other-value2-${requestScope.someBoolean ? 'a' : 'b'}.jsp",
nudef.getAttribute("something").getExpressionObject().getExpression());
}

/**
* Test method for
* {@link PatternUtil#replacePlaceholders(Definition, String, Object[])}.
*/
@Test
public void testReplacePlaceholdersEL_twice() {
Map<String, Attribute> attributes = new HashMap<String, Attribute>();
Attribute attribute = new Attribute("some-${requestScope.firstVariable}-${requestScope.secondVariable}.jsp");
attribute.setExpressionObject(new Expression((String)attribute.getValue()));
attributes.put("something", attribute);
Definition definition = new Definition("definitionName", new Attribute("template"), attributes);
Definition nudef = PatternUtil.replacePlaceholders(definition, "nudef", "value0", "value1", "value2", "value3");
assertEquals("nudef", nudef.getName());

assertEquals(
"some-${requestScope.firstVariable}-${requestScope.secondVariable}.jsp",
nudef.getAttribute("something").getValue());

assertEquals(
"some-${requestScope.firstVariable}-${requestScope.secondVariable}.jsp",
nudef.getAttribute("something").getExpressionObject().getExpression());
}

/**
* Test method for
* {@link PatternUtil#replacePlaceholders(Definition, String, Object[])}.
*/
@Test
public void testReplacePlaceholdersEL_options() {
Map<String, Attribute> attributes = new HashMap<String, Attribute>();
Attribute attribute = new Attribute("{1}/{options[my_fallback}}/some-other-{2}-${requestScope.someVariable}.jsp");
attribute.setExpressionObject(new Expression((String)attribute.getValue()));
attributes.put("something", attribute);
Definition definition = new Definition("definitionName", new Attribute("template"), attributes);
Definition nudef = PatternUtil.replacePlaceholders(definition, "nudef", "value0", "value1", "value2", "value3");
assertEquals("nudef", nudef.getName());

assertEquals(
"value1/{options[my_fallback}}/some-other-value2-${requestScope.someVariable}.jsp",
nudef.getAttribute("something").getValue());

assertEquals(
"value1/{options[my_fallback}}/some-other-value2-${requestScope.someVariable}.jsp",
nudef.getAttribute("something").getExpressionObject().getExpression());
}
}

0 comments on commit 951d6a2

Please sign in to comment.