You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2013/06/03 10:47:16 UTC
svn commit: r1488897 - in
/struts/struts2/branches/STRUTS_2_3_14_2_X/xwork-core/src:
main/java/com/opensymphony/xwork2/util/OgnlTextParser.java
test/java/com/opensymphony/xwork2/util/TextParseUtilTest.java
Author: lukaszlenart
Date: Mon Jun 3 08:47:16 2013
New Revision: 1488897
URL: http://svn.apache.org/r1488897
Log:
WW-4090 Removes double evaluation of parsed expression
Modified:
struts/struts2/branches/STRUTS_2_3_14_2_X/xwork-core/src/main/java/com/opensymphony/xwork2/util/OgnlTextParser.java
struts/struts2/branches/STRUTS_2_3_14_2_X/xwork-core/src/test/java/com/opensymphony/xwork2/util/TextParseUtilTest.java
Modified: struts/struts2/branches/STRUTS_2_3_14_2_X/xwork-core/src/main/java/com/opensymphony/xwork2/util/OgnlTextParser.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_3_14_2_X/xwork-core/src/main/java/com/opensymphony/xwork2/util/OgnlTextParser.java?rev=1488897&r1=1488896&r2=1488897&view=diff
==============================================================================
--- struts/struts2/branches/STRUTS_2_3_14_2_X/xwork-core/src/main/java/com/opensymphony/xwork2/util/OgnlTextParser.java (original)
+++ struts/struts2/branches/STRUTS_2_3_14_2_X/xwork-core/src/main/java/com/opensymphony/xwork2/util/OgnlTextParser.java Mon Jun 3 08:47:16 2013
@@ -11,17 +11,16 @@ public class OgnlTextParser implements T
// deal with the "pure" expressions first!
//expression = expression.trim();
Object result = expression;
+ int pos = 0;
+
for (char open : openChars) {
int loopCount = 1;
- int pos = 0;
-
//this creates an implicit StringBuffer and shouldn't be used in the inner loop
final String lookupChars = open + "{";
while (true) {
int start = expression.indexOf(lookupChars, pos);
if (start == -1) {
- pos = 0;
loopCount++;
start = expression.indexOf(lookupChars);
}
Modified: struts/struts2/branches/STRUTS_2_3_14_2_X/xwork-core/src/test/java/com/opensymphony/xwork2/util/TextParseUtilTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_3_14_2_X/xwork-core/src/test/java/com/opensymphony/xwork2/util/TextParseUtilTest.java?rev=1488897&r1=1488896&r2=1488897&view=diff
==============================================================================
--- struts/struts2/branches/STRUTS_2_3_14_2_X/xwork-core/src/test/java/com/opensymphony/xwork2/util/TextParseUtilTest.java (original)
+++ struts/struts2/branches/STRUTS_2_3_14_2_X/xwork-core/src/test/java/com/opensymphony/xwork2/util/TextParseUtilTest.java Mon Jun 3 08:47:16 2013
@@ -97,6 +97,24 @@ public class TextParseUtilTest extends X
assertEquals("count must be between 123 and 456, current value is 98765.", s);
}
+ public void testNestedExpression() throws Exception {
+ ValueStack stack = ActionContext.getContext().getValueStack();
+ stack.push(new HashMap<String, Object>() {{ put("foo", "${%{1+1}}"); }});
+ String s = TextParseUtil.translateVariables("${foo}", stack);
+ assertEquals("${%{1+1}}", s);
+ stack.pop();
+ }
+
+ public void testMixedOpenChars() throws Exception {
+ ValueStack stack = ActionContext.getContext().getValueStack();
+ stack.push(new HashMap<String, Object>() {{ put("foo", "bar"); }});
+ String s = TextParseUtil.translateVariables("${foo}-%{foo}", stack);
+ assertEquals("bar-bar", s);
+ s = TextParseUtil.translateVariables("%{foo}-${foo}", stack);
+ assertEquals("%{foo}-bar", s); // this is bad, but it is the only way not to double evaluate passed expression
+ stack.pop();
+ }
+
public void testCommaDelimitedStringToSet() {
assertEquals(0, TextParseUtil.commaDelimitedStringToSet("").size());
assertEquals(new HashSet<String>(Arrays.asList("foo", "bar", "tee")),
@@ -132,10 +150,13 @@ public class TextParseUtilTest extends X
public void testTranslateVariablesRecursive() {
ValueStack stack = ActionContext.getContext().getValueStack();
- stack.push(new HashMap<String, Object>() {{ put("foo", "${1+1}"); }});
+ stack.push(new HashMap<String, Object>() {{ put("foo", "${1+1}"); put("bar", "${${1+2}}"); }});
Object s = TextParseUtil.translateVariables('$', "foo: ${foo}", stack, String.class, null, 2);
assertEquals("foo: 2", s);
+
+ s = TextParseUtil.translateVariables('$', "foo: ${bar}", stack, String.class, null, 1);
+ assertEquals("foo: ${${1+2}}", s);
}
public void testTranslateVariablesWithNull() {