From: PJ Fanning Date: Mon, 1 Aug 2022 16:06:59 +0000 (+0000) Subject: [bug-66181] fix issue with evaluation of blank string in VALUE function X-Git-Tag: REL_5_2_3~94 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=633baa45eb3cb314a7128ad4f010071fe1e4eb84;p=poi.git [bug-66181] fix issue with evaluation of blank string in VALUE function git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903171 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index 1d6cac19b4..80a7a140d5 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -3701,8 +3701,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { assertEquals(CellType.ERROR, a1.getCachedFormulaResultType()); FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator(); CellValue cv1 = evaluator.evaluate(a1); - //this next line should probably return CellType.ERROR - assertEquals(CellType.NUMERIC, cv1.getCellType()); + assertEquals(CellType.ERROR, cv1.getCellType()); + assertEquals(ErrorEval.VALUE_INVALID.getErrorCode(), cv1.getErrorValue()); } } } \ No newline at end of file diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/Value.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/Value.java index d2a1f24fc7..b3c6cb3c45 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/functions/Value.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/Value.java @@ -23,6 +23,7 @@ import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.OperandResolver; import org.apache.poi.ss.formula.eval.ValueEval; import org.apache.poi.ss.usermodel.DateUtil; +import org.apache.poi.util.StringUtil; import java.time.DateTimeException; @@ -52,6 +53,9 @@ public final class Value extends Fixed1ArgFunction implements ArrayFunction { return e.getErrorEval(); } String strText = OperandResolver.coerceValueToString(veText); + if (StringUtil.isBlank(strText)) { + return ErrorEval.VALUE_INVALID; + } Double result = convertTextToNumber(strText); if (result == null) result = parseDateTime(strText); if (result == null) { diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestValue.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestValue.java index 83bf4b6c13..03f8aab85a 100644 --- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestValue.java +++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestValue.java @@ -93,5 +93,6 @@ final class TestValue { confirmValueError(",300"); confirmValueError("0.233,4"); confirmValueError("1e2.5"); + confirmValueError(""); } }