You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2012/04/05 16:54:57 UTC
svn commit: r1309890 - in
/ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/string:
FlexibleStringExpander.java test/FlexibleStringExpanderTests.java
Author: adrianc
Date: Thu Apr 5 14:54:56 2012
New Revision: 1309890
URL: http://svn.apache.org/viewvc?rev=1309890&view=rev
Log:
Disable support for nested scripts in FlexibleStringExpander.
Modified:
ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java
ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java
Modified: ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java?rev=1309890&r1=1309889&r2=1309890&view=diff
==============================================================================
--- ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java (original)
+++ ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java Thu Apr 5 14:54:56 2012
@@ -60,6 +60,26 @@ public abstract class FlexibleStringExpa
protected static final UtilCache<Key, FlexibleStringExpander> exprCache = UtilCache.createUtilCache("flexibleStringExpander.ExpressionCache");
protected static final FlexibleStringExpander nullExpr = new ConstSimpleElem(new char[0]);
+ /**
+ * Returns <code>true</code> if <code>fse</code> contains a script.
+ * @param fse The <code>FlexibleStringExpander</code> to test
+ * @return <code>true</code> if <code>fse</code> contains a script
+ */
+ public static boolean containsScript(FlexibleStringExpander fse) {
+ if (fse instanceof BshElem || fse instanceof GroovyElem) {
+ return true;
+ }
+ if (fse instanceof Elements) {
+ Elements fseElements = (Elements) fse;
+ for (FlexibleStringExpander childElement : fseElements.childElems) {
+ if (containsScript(childElement)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
/** Evaluate an expression and return the result as a <code>String</code>.
* Null expressions return <code>null</code>.
* A null <code>context</code> argument will return the original expression.
@@ -701,6 +721,9 @@ public abstract class FlexibleStringExpa
String str = (String) obj;
if (str.contains(openBracket)) {
FlexibleStringExpander fse = FlexibleStringExpander.getInstance(str);
+ if (containsScript(fse)) {
+ throw new UnsupportedOperationException("Nested scripts are not supported");
+ }
return fse.get(context, timeZone, locale);
}
} catch (ClassCastException e) {}
Modified: ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java?rev=1309890&r1=1309889&r2=1309890&view=diff
==============================================================================
--- ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java (original)
+++ ofbiz/branches/release11.04/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java Thu Apr 5 14:54:56 2012
@@ -286,6 +286,16 @@ public class FlexibleStringExpanderTests
List<String> testList = new ArrayList<String>();
testList.add("World");
testMap.put("testList", testList);
+ testMap.put("testScript", "${groovy:return null;}");
+ UnsupportedOperationException caught = null;
+ try {
+ FlexibleStringExpander fse = FlexibleStringExpander.getInstance("${testScript}");
+ fse.expandString(testMap);
+ } catch (UnsupportedOperationException e) {
+ caught = e;
+ } finally {
+ assertNotNull("UnsupportedOperationException thrown for nested script", caught);
+ }
fseTest("null FlexibleStringExpander, null map", null, null, null, null, "", null, true);
fseTest("null FlexibleStringExpander", null, testMap, null, null, "", null, true);
fseTest("null context", "Hello World!", null, null, null, "Hello World!", null, false);