Author: adrianc
Date: Thu Apr 5 15:18:22 2012 New Revision: 1309897 URL: http://svn.apache.org/viewvc?rev=1309897&view=rev Log: Disable support for nested scripts in FlexibleStringExpander. Modified: ofbiz/branches/release10.04/ (props changed) ofbiz/branches/release10.04/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java ofbiz/branches/release10.04/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java Propchange: ofbiz/branches/release10.04/ ------------------------------------------------------------------------------ Merged /ofbiz/branches/release11.04:r1309890 Modified: ofbiz/branches/release10.04/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release10.04/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java?rev=1309897&r1=1309896&r2=1309897&view=diff ============================================================================== --- ofbiz/branches/release10.04/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java (original) +++ ofbiz/branches/release10.04/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java Thu Apr 5 15:18:22 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. @@ -697,6 +717,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/release10.04/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release10.04/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java?rev=1309897&r1=1309896&r2=1309897&view=diff ============================================================================== --- ofbiz/branches/release10.04/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java (original) +++ ofbiz/branches/release10.04/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java Thu Apr 5 15:18:22 2012 @@ -283,6 +283,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); |
Free forum by Nabble | Edit this page |