[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
This commit is contained in:
PJ Fanning 2022-08-01 16:06:59 +00:00
parent f3a1d6ac92
commit 633baa45eb
3 changed files with 7 additions and 2 deletions

View 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());
}
}
}

View 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) {

View File

@ -93,5 +93,6 @@ final class TestValue {
confirmValueError(",300");
confirmValueError("0.233,4");
confirmValueError("1e2.5");
confirmValueError("");
}
}