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 2010/04/25 14:58:46 UTC

svn commit: r937792 - in /poi/trunk: src/documentation/content/xdocs/ src/ooxml/java/org/apache/poi/xssf/model/ src/ooxml/testcases/org/apache/poi/xssf/model/ test-data/spreadsheet/

Author: yegor
Date: Sun Apr 25 12:58:45 2010
New Revision: 937792

URL: http://svn.apache.org/viewvc?rev=937792&view=rev
Log:
 Avoid writing malformed CDATA blocks in sharedStrings.xml, see Bugzill 48936

Added:
    poi/trunk/test-data/spreadsheet/48936-strings.txt
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.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=937792&r1=937791&r2=937792&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Sun Apr 25 12:58:45 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-SNAPSHOT" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">48936 - Avoid writing malformed CDATA blocks in sharedStrings.xml</action>
            <action dev="POI-DEVELOPERS" type="add">49026 - Added implementation for TEXT()  </action>
            <action dev="POI-DEVELOPERS" type="add">49025 - Added implementation for TRUNC()  </action>
            <action dev="POI-DEVELOPERS" type="fix">49147 - Properly close internal InputStream in ExtractorFactory#createExtractor(File)</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java?rev=937792&r1=937791&r2=937792&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java Sun Apr 25 12:58:45 2010
@@ -84,7 +84,7 @@ public class SharedStringsTable extends 
      */
     private int uniqueCount;
 
-    private SstDocument _sstDoc;
+    public SstDocument _sstDoc;
 
     public SharedStringsTable() {
         super();
@@ -195,6 +195,10 @@ public class SharedStringsTable extends 
      */
     public void writeTo(OutputStream out) throws IOException {
         XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS);
+        // the following two lines turn off writing CDATA
+        // see Bugzilla 48936
+        options.setSaveCDataLengthThreshold(1000000);
+        options.setSaveCDataEntityCountThreshold(-1);
 
         //re-create the sst table every time saving a workbook
         CTSst sst = _sstDoc.getSst();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java?rev=937792&r1=937791&r2=937792&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/model/TestSharedStringsTable.java Sun Apr 25 12:58:45 2010
@@ -18,12 +18,18 @@
 package org.apache.poi.xssf.model;
 
 import java.util.List;
+import java.util.ArrayList;
+import java.io.*;
 
 import junit.framework.TestCase;
 
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.usermodel.XSSFRichTextString;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.POIXMLException;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRPrElt;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
@@ -125,4 +131,49 @@ public final class TestSharedStringsTabl
             assertEquals(st1.toString(), st2.toString());
         }
     }
+
+    /**
+     * Test for Bugzilla 48936
+     *
+     * A specific sequence of strings can result in broken CDATA section in sharedStrings.xml file.
+     *
+     * @author Philippe Laflamme
+     */
+    public void testBug48936() throws IOException {
+        Workbook w = new XSSFWorkbook();
+        Sheet s = w.createSheet();
+        int i = 0;
+        List<String> lst = readStrings("48936-strings.txt");
+        for (String str : lst) {
+            s.createRow(i++).createCell(0).setCellValue(str);
+        }
+
+        try {
+            w = XSSFTestDataSamples.writeOutAndReadBack(w);
+        } catch (POIXMLException e){
+            fail("Detected Bug #48936");        
+        }
+        s = w.getSheetAt(0);
+        i = 0;
+        for (String str : lst) {
+            String val = s.getRow(i++).getCell(0).getStringCellValue();
+            assertEquals(str, val);
+        }
+    }
+
+    private List<String> readStrings(String filename) throws IOException {
+        List<String> strs = new ArrayList<String>();
+        POIDataSamples samples = POIDataSamples.getSpreadSheetInstance();
+        BufferedReader br = new BufferedReader(
+                new InputStreamReader(samples.openResourceAsStream(filename)));
+        String s;
+        while ((s = br.readLine()) != null) {
+            if (s.trim().length() > 0) {
+                strs.add(s.trim());
+            }
+        }
+        br.close();
+        return strs;
+    }
+
 }

Added: poi/trunk/test-data/spreadsheet/48936-strings.txt
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/48936-strings.txt?rev=937792&view=auto
==============================================================================
--- poi/trunk/test-data/spreadsheet/48936-strings.txt (added)
+++ poi/trunk/test-data/spreadsheet/48936-strings.txt Sun Apr 25 12:58:45 2010
@@ -0,0 +1,81 @@
+[IntegrityCheck-ERROR[MALE[50.0 < x < 199.0], FEMALE[50.0 < x < 199.0]], IntegrityCheck-WARNING[MALE[61.0 < x < 126.0], FEMALE[47.0 < x < 119.0]]]
+Computing[($1 + $2 + $3)/3,[Instrument[BloodPressure, RES_FIRST_DIASTOLIC_BP], Instrument[BloodPressure, RES_SEC_DIASTOLIC_BP], Instrument[BloodPressure, RES_THIRD_DIASTOLIC_BP]]]
+COMPUTED
+BloodPressure
+BloodPressure
+Average Pulse Rate
+Moyenne des lectures de pouls
+Computing[($1 + $2 + $3)/3,[Instrument[BloodPressure, RES_FIRST_PULSE_RATE], Instrument[BloodPressure, RES_SEC_PULSE_RATE], Instrument[BloodPressure, RES_THIRD_PULSE_RATE]]]
+COMPUTED
+BloodPressure
+BloodPressure
+Average Systolic Blood Pressure
+Pression artérielle systolique moyenne
+Computing[($1 + $2 + $3)/3,[Instrument[BloodPressure, RES_FIRST_SYSTOLIC_BP], Instrument[BloodPressure, RES_SEC_SYSTOLIC_BP], Instrument[BloodPressure, RES_THIRD_SYSTOLIC_BP]]]
+COMPUTED
+BloodPressure
+BloodPressure
+BloodPressure
+BloodPressure
+BloodPressure
+BloodPressure
+BloodPressure
+BloodPressure
+BloodPressure
+Armband size used
+Taille du brassard utilisé
+MANUAL
+Small
+Petit
+Medium
+Moyen
+Large
+Grand
+Extra Large
+Très grand
+BloodPressure
+BloodPressure
+Arm suggested to be used for measurement
+Bras suggéré pour la mesure
+Variable[Onyx.CIPreliminaryQuestionnaire.BP_ARM_CHOSEN]
+AUTOMATIC
+false
+BloodPressure
+BloodPressure
+What arm was actually used for the measurements?
+Quel bras a été utilisé pour les mesures?
+MANUAL
+Left
+Gauche
+Right
+Droit
+BloodPressure
+BloodPressure
+Circumference of upper arm at midpoint
+Circonférence du haut du bras
+[IntegrityCheck-ERROR[MALE[17.0 < x < 50.0], FEMALE[17.0 < x < 50.0]]]
+MANUAL
+BloodPressure
+BloodPressure
+Diastolic Blood Pressure reading (1)
+Lecture de la pression artérielle diastolique (1)
+[IntegrityCheck-ERROR[MALE[30 < x < 200 || ], FEMALE[30 < x < 200 || ]], IntegrityCheck-WARNING[MALE[51 < x < 96 || ], FEMALE[51 < x < 96 || ]], IntegrityCheck-ERROR[x < RES_FIRST_SYSTOLIC_BP]]
+MANUAL
+BloodPressure
+BloodPressure
+Pulse Rate reading (1)
+Lecture de pouls (1)
+[IntegrityCheck-ERROR[MALE[30 < x < 200 || ], FEMALE[30 < x < 200 || ]], IntegrityCheck-WARNING[MALE[40 < x < 100 || ], FEMALE[40 < x < 100 || ]]]
+MANUAL
+BloodPressure
+BloodPressure
+Systolic Blood Pressure reading (1)
+Lecture de la pression artérielle systolique  (1)
+[IntegrityCheck-ERROR[MALE[30 < x < 300 || ], FEMALE[30 < x < 300 || ]], IntegrityCheck-WARNING[MALE[77 < x < 192 || ], FEMALE[77 < x < 192 || ]]]
+MANUAL
+BloodPressure
+BloodPressure
+Diastolic Blood Pressure reading (2)
+Lecture de la pression artérielle diastolique (2)
+[IntegrityCheck-ERROR[MALE[30 < x < 200 || ], FEMALE[30 < x < 200 || ]], IntegrityCheck-WARNING[MALE[51 < x < 96 || ], FEMALE[51 < x < 96 || ]], IntegrityCheck-ERROR[x < RES_SEC_SYSTOLIC_BP]]
+



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