`svn merge -c1594481 ^/tiles/framework/branches/TILES_3_0_X .`
| 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
diff --git a/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java b/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java
index f84d0f7..9444897 100644
--- a/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java
+++ b/tiles-core/src/main/java/org/apache/tiles/definition/pattern/PatternUtil.java
@@ -52,7 +52,7 @@
/** 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.
diff --git a/tiles-core/src/test/java/org/apache/tiles/definition/pattern/PatternUtilTest.java b/tiles-core/src/test/java/org/apache/tiles/definition/pattern/PatternUtilTest.java
index ddbfacf..17a5cf0 100644
--- a/tiles-core/src/test/java/org/apache/tiles/definition/pattern/PatternUtilTest.java
+++ b/tiles-core/src/test/java/org/apache/tiles/definition/pattern/PatternUtilTest.java
@@ -250,4 +250,73 @@
"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());
+ }
}