diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 1369190d9..01c8b0891 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 53360 - Fixed SXSSF to correctly write text before escaped Unicode control character Change HSMF Types to have full data on ID, Name and Length, rather than just being a simple ID 48469 - Updated case study 53476 - Support Complex Name in formulas diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java index 521f9d56e..f6c98317f 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java @@ -278,6 +278,9 @@ public class SheetDataWriter { // the same rule applies to unicode surrogates and "not a character" symbols. if( c < ' ' || Character.isLowSurrogate(c) || Character.isHighSurrogate(c) || ('\uFFFE' <= c && c <= '\uFFFF')) { + if (counter > last) { + _out.write(chars, last, counter - last); + } _out.write('?'); last = counter + 1; } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java index 72258e411..ef9149cbf 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java @@ -154,6 +154,14 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { tmp = wr.getTempFile(); assertTrue(tmp.getName().startsWith("poi-sxssf-sheet-xml")); assertTrue(tmp.getName().endsWith(".gz")); + + //Test escaping of Unicode control characters + wb = new SXSSFWorkbook(); + wb.createSheet("S1").createRow(0).createCell(0).setCellValue("value\u0019"); + XSSFWorkbook xssfWorkbook = (XSSFWorkbook) SXSSFITestDataProvider.instance.writeOutAndReadBack(wb); + Cell cell = xssfWorkbook.getSheet("S1").getRow(0).getCell(0); + assertEquals("value?", cell.getStringCellValue()); + } public void testGZipSheetdataWriter(){