aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java34
-rw-r--r--poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java2
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java1
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java1
-rw-r--r--poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java34
-rw-r--r--test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-6483562584932352.xlsbin0 -> 13134 bytes
-rw-r--r--test-data/spreadsheet/stress.xlsbin64512 -> 65024 bytes
7 files changed, 71 insertions, 1 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java
index fe4aa0a00a..bc6ddf0c62 100644
--- a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java
+++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFDataFormat.java
@@ -21,6 +21,7 @@ import static org.apache.poi.xssf.XSSFTestDataSamples.openSampleWorkbook;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
+import java.util.Date;
import org.apache.poi.ss.formula.ConditionalFormattingEvaluator;
import org.apache.poi.ss.formula.WorkbookEvaluatorProvider;
@@ -120,4 +121,37 @@ public final class TestXSSFDataFormat extends BaseTestDataFormat {
assertEquals("6.75", formatter.formatCellValue(d1));
}
}
+
+ @Test
+ public void testFormatCellValue() throws IOException {
+ DataFormatter df = new DataFormatter();
+
+ assertEquals("", df.formatCellValue(null));
+
+ try (Workbook wb = new XSSFWorkbook()) {
+ Cell cell = wb.createSheet("test").createRow(0).createCell(0);
+ assertEquals("", df.formatCellValue(cell));
+
+ cell.setCellValue(123);
+ assertEquals("123", df.formatCellValue(cell));
+
+ cell.setCellValue(new Date(234092383));
+ assertEquals("25571.75107", df.formatCellValue(cell));
+
+ cell.setCellValue("abcdefgh");
+ assertEquals("abcdefgh", df.formatCellValue(cell));
+
+ cell.setCellValue(true);
+ assertEquals("TRUE", df.formatCellValue(cell));
+
+ CellStyle cellStyle = wb.createCellStyle();
+ cellStyle.setDataFormat((short)14);
+ cell.setCellStyle(cellStyle);
+ cell.setCellValue(new Date(234092383));
+ assertEquals("1/3/70", df.formatCellValue(cell));
+
+ cellStyle.setDataFormat((short)9999);
+ assertEquals("25571.751069247686", df.formatCellValue(cell));
+ }
+ }
}
diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java b/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java
index 35e5ff55d6..f94e6893f7 100644
--- a/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java
+++ b/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java
@@ -922,7 +922,7 @@ public class DataFormatter {
sdf.setTimeZone(LocaleUtil.getUserTimeZone());
dateFormat = sdf;
} else {
- dateFormat = defaultNumFormat;
+ dateFormat = defaultDateformat;
}
}
synchronized (dateFormat) {
diff --git a/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java b/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java
index 491d68d159..d23f1dbece 100644
--- a/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java
+++ b/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java
@@ -46,6 +46,7 @@ class TestBiffViewer extends BaseTestIteratingXLS {
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5889658057523200.xls", IndexOutOfBoundsException.class);
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5175219985448960.xls", IndexOutOfBoundsException.class);
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6137883240824832.xls", IndexOutOfBoundsException.class);
+ excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6483562584932352.xls", IndexOutOfBoundsException.class);
return excludes;
}
diff --git a/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java b/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java
index 7f1c1f4561..34359e1d2e 100644
--- a/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java
+++ b/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java
@@ -49,6 +49,7 @@ class TestRecordLister extends BaseTestIteratingXLS {
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5889658057523200.xls", IndexOutOfBoundsException.class);
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-5175219985448960.xls", RecordFormatException.class);
excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6137883240824832.xls", RecordFormatException.class);
+ excludes.put("clusterfuzz-testcase-minimized-POIHSSFFuzzer-6483562584932352.xls", RecordFormatException.class);
return excludes;
}
diff --git a/poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java b/poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java
index 0d6c1af5b9..31cfa031b0 100644
--- a/poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java
+++ b/poi/src/test/java/org/apache/poi/ss/usermodel/TestDataFormatter.java
@@ -35,6 +35,8 @@ import java.util.Locale;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
+import javax.swing.text.DateFormatter;
+
import org.apache.poi.POITestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
@@ -1162,4 +1164,36 @@ class TestDataFormatter {
return true;
}
+ @Test
+ public void testFormatCellValue() throws IOException {
+ DataFormatter df = new DataFormatter();
+
+ assertEquals("", df.formatCellValue(null));
+
+ try (Workbook wb = new HSSFWorkbook()) {
+ Cell cell = wb.createSheet("test").createRow(0).createCell(0);
+ assertEquals("", df.formatCellValue(cell));
+
+ cell.setCellValue(123);
+ assertEquals("123", df.formatCellValue(cell));
+
+ cell.setCellValue(new Date(234092383));
+ assertEquals("25571.75107", df.formatCellValue(cell));
+
+ cell.setCellValue("abcdefgh");
+ assertEquals("abcdefgh", df.formatCellValue(cell));
+
+ cell.setCellValue(true);
+ assertEquals("TRUE", df.formatCellValue(cell));
+
+ CellStyle cellStyle = wb.createCellStyle();
+ cellStyle.setDataFormat((short)14);
+ cell.setCellStyle(cellStyle);
+ cell.setCellValue(new Date(234092383));
+ assertEquals("1/3/70", df.formatCellValue(cell));
+
+ cellStyle.setDataFormat((short)9999);
+ assertEquals("25571.751069247686", df.formatCellValue(cell));
+ }
+ }
}
diff --git a/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-6483562584932352.xls b/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-6483562584932352.xls
new file mode 100644
index 0000000000..f2ec6f113b
--- /dev/null
+++ b/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIHSSFFuzzer-6483562584932352.xls
Binary files differ
diff --git a/test-data/spreadsheet/stress.xls b/test-data/spreadsheet/stress.xls
index 98ce7f52d6..0c9f727189 100644
--- a/test-data/spreadsheet/stress.xls
+++ b/test-data/spreadsheet/stress.xls
Binary files differ