You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2012/02/28 14:52:10 UTC

svn commit: r1294657 - in /poi/trunk/src: documentation/content/xdocs/status.xml ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java

Author: yegor
Date: Tue Feb 28 13:52:09 2012
New Revision: 1294657

URL: http://svn.apache.org/viewvc?rev=1294657&view=rev
Log:
Bugzilla 52784 - replace ISO control characters with question marks in SXSSF to be consistent with XSSF

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1294657&r1=1294656&r2=1294657&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue Feb 28 13:52:09 2012
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta6" date="2012-??-??">
+           <action dev="poi-developers" type="fix">52784 - replace ISO control characters with question marks in SXSSF to be consistent with XSSF </action>
            <action dev="poi-developers" type="add">52057 - updated formula test framework to be aware of recently added Functions </action>
            <action dev="poi-developers" type="add">52574 - support setting header / footer page margins in HSSF </action>
            <action dev="poi-developers" type="add">52583 - fixed WorkbookUtil#createSafeSheetName to escape colon </action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java?rev=1294657&r1=1294656&r2=1294657&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java Tue Feb 28 13:52:09 2012
@@ -250,6 +250,7 @@ public class SheetDataWriter {
                     break;
                 // Special characters
                 case '\n':
+                case '\r':
                     if (counter > last) {
                         _out.write(chars, last, counter - last);
                     }
@@ -263,13 +264,6 @@ public class SheetDataWriter {
                     _out.write("&#x9;");
                     last = counter + 1;
                     break;
-                case '\r':
-                    if (counter > last) {
-                        _out.write(chars, last, counter - last);
-                    }
-                    _out.write("&#xd;");
-                    last = counter + 1;
-                    break;
                 case 0xa0:
                     if (counter > last) {
                         _out.write(chars, last, counter - last);
@@ -278,7 +272,14 @@ public class SheetDataWriter {
                     last = counter + 1;
                     break;
                 default:
-                    if (c < ' ' || c > 127) {
+                    // YK: XmlBeans silently replaces all ISO control characters ( < 32) with question marks.
+                    // the same rule applies to unicode surrogates and "not a character" symbols.
+                    if( c < ' ' || Character.isLowSurrogate(c) || Character.isHighSurrogate(c) ||
+                            ('\uFFFE' <= c && c <= '\uFFFF')) {
+                        _out.write('?');
+                        last = counter + 1;
+                    }
+                    else if (c > 127) {
                         if (counter > last) {
                             _out.write(chars, last, counter - last);
                         }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java?rev=1294657&r1=1294656&r2=1294657&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFCell.java Tue Feb 28 13:52:09 2012
@@ -21,6 +21,8 @@ package org.apache.poi.xssf.streaming;
 
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.SXSSFITestDataProvider;
+import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 /**
  *
@@ -66,12 +68,40 @@ public class TestSXSSFCell extends BaseT
         Sheet sh = wb.createSheet();
         Row row = sh.createRow(0);
         Cell cell = row.createCell(0);
-        String sval = "<>\t\r\n\u00a0 &\"POI\'\u2122";
+        String sval = "\u0000\u0002\u0012<>\t\n\u00a0 &\"POI\'\u2122";
         cell.setCellValue(sval);
 
         wb = _testDataProvider.writeOutAndReadBack(wb);
 
-        assertEquals(sval, wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
+        // invalid characters are replaced with question marks
+        assertEquals("???<>\t\n\u00a0 &\"POI\'\u2122", wb.getSheetAt(0).getRow(0).getCell(0).getStringCellValue());
+
+    }
+
+    public void testEncodingbeloAscii(){
+        Workbook xwb = new XSSFWorkbook();
+        Cell xCell = xwb.createSheet().createRow(0).createCell(0);
+
+        Workbook swb = new SXSSFWorkbook();
+        Cell sCell = swb.createSheet().createRow(0).createCell(0);
+
+        StringBuffer sb = new StringBuffer();
+        // test all possible characters
+        for(int i = 0; i < Character.MAX_VALUE; i++) sb.append((char)i) ;
+
+        String str = sb.toString();
+
+        xCell.setCellValue(str);
+        assertEquals(str, xCell.getStringCellValue());
+        sCell.setCellValue(str);
+        assertEquals(str, sCell.getStringCellValue());
+
+        xwb = XSSFITestDataProvider.instance.writeOutAndReadBack(xwb);
+        swb = SXSSFITestDataProvider.instance.writeOutAndReadBack(swb);
+        xCell = xwb.getSheetAt(0).createRow(0).createCell(0);
+        sCell = swb.getSheetAt(0).createRow(0).createCell(0);
+
+        assertEquals(xCell.getStringCellValue(), sCell.getStringCellValue());
 
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org