|
Author: doogie
Date: Sun Feb 21 01:32:00 2010 New Revision: 912281 URL: http://svn.apache.org/viewvc?rev=912281&view=rev Log: BUG FIX: Fix parsing of currency when there is no variable, and no trailing ). Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java?rev=912281&r1=912280&r2=912281&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/FlexibleStringExpander.java Sun Feb 21 01:32:00 2010 @@ -209,16 +209,20 @@ if (end == -1) { end = origLen; } - String subExpression = expression.substring(start + 2, end); // Evaluation sequence is important - do not change it if (escapedExpression) { strElems.add(new ConstElem(expression.substring(start, end + 1))); - } else if (subExpression.contains("?currency(")) { - strElems.add(new CurrElem(subExpression)); - } else if (subExpression.contains(openBracket)) { - strElems.add(new NestedVarElem(subExpression)); } else { - strElems.add(new VarElem(subExpression)); + String subExpression = expression.substring(start + 2, end); + int currencyPos = subExpression.indexOf("?currency("); + int closeParen = currencyPos > 0 ? subExpression.indexOf(")", currencyPos + 10) : -1; + if (closeParen != -1) { + strElems.add(new CurrElem(subExpression)); + } else if (subExpression.contains(openBracket)) { + strElems.add(new NestedVarElem(subExpression)); + } else { + strElems.add(new VarElem(subExpression)); + } } } // reset the current index to after the expression, and the start to the beginning of the next expression Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java?rev=912281&r1=912280&r2=912281&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/string/test/FlexibleStringExpanderTests.java Sun Feb 21 01:32:00 2010 @@ -82,14 +82,13 @@ parserTest("currency", "${?currency(usd)", "${?currency(usd)"); parserTest("currency", "${price?currency(usd", "${price?currency(usd"); parserTest("currency", "${price?currency(usd)", "${price?currency(usd)"); - // CurrElem doesn't protected itself - //parserTest("currency", "${?currency(}", "${?currency(}"); + parserTest("currency", "${?currency(}", "?currency("); parserTest("currency", "${?currency()}", "?currency()"); - //parserTest("currency", "${?currency(usd}", "${?currency(usd}"); + parserTest("currency", "${?currency(usd}", "?currency(usd"); parserTest("currency", "${?currency(usd)}", "?currency(usd)"); - //parserTest("currency", "${price?currency(}", "${price?currency(}"); + parserTest("currency", "${price?currency(}", "price?currency("); parserTest("currency", "${price?currency()}", "price?currency()"); - //parserTest("currency", "${price?currency(usd}", "${price?currency(usd}"); + parserTest("currency", "${price?currency(usd}", "price?currency(usd"); parserTest("currency", "${price?currency(usd)}", "price?currency(usd)"); parserTest("currency", "a${price?currency(usd)}b", "a${price?currency(usd)}b"); } |
| Free forum by Nabble | Edit this page |
