]> source.dussan.org Git - poi.git/commitdiff
[bug-66181] fix issue with evaluation of blank string in VALUE function
authorPJ Fanning <fanningpj@apache.org>
Mon, 1 Aug 2022 16:06:59 +0000 (16:06 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 1 Aug 2022 16:06:59 +0000 (16:06 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903171 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
poi/src/main/java/org/apache/poi/ss/formula/functions/Value.java
poi/src/test/java/org/apache/poi/ss/formula/functions/TestValue.java

index 1d6cac19b44d2c8f4cc5ea334937b1a5b50ea0d9..80a7a140d552528ddb037a96acd2fee6ba9a8331 100644 (file)
@@ -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
index d2a1f24fc7c958eae5095c9193ee540a38fa19a9..b3c6cb3c45a2a790b176d6c50ae14c68070b5a28 100644 (file)
@@ -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) {
index 83bf4b6c1383d5d97b2bcc50d54a2ae5f92c381c..03f8aab85a47c3f799d7d03cc2a7e49b26796861 100644 (file)
@@ -93,5 +93,6 @@ final class TestValue {
         confirmValueError(",300");
         confirmValueError("0.233,4");
         confirmValueError("1e2.5");
+        confirmValueError("");
     }
 }