poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1766065 - in /poi/trunk: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java test-data/spreadsheet/60289.xlsx
Date Fri, 21 Oct 2016 16:31:52 GMT
Author: centic
Date: Fri Oct 21 16:31:51 2016
New Revision: 1766065

URL: http://svn.apache.org/viewvc?rev=1766065&view=rev
Log:
Bug 60289: Fix handling of unicode escapes with lowercase hex-chars

Added:
    poi/trunk/test-data/spreadsheet/60289.xlsx
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java?rev=1766065&r1=1766064&r2=1766065&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRichTextString.java Fri Oct
21 16:31:51 2016
@@ -75,7 +75,7 @@ import org.openxmlformats.schemas.spread
  * </blockquote>
  */
 public class XSSFRichTextString implements RichTextString {
-    private static final Pattern utfPtrn = Pattern.compile("_x([0-9A-F]{4})_");
+    private static final Pattern utfPtrn = Pattern.compile("_x([0-9A-Fa-f]{4})_");
 
     private CTRst st;
     private StylesTable styles;
@@ -244,12 +244,13 @@ public class XSSFRichTextString implemen
         if(ctFont.sizeOfShadowArray() > 0) pr.addNewShadow().setVal(ctFont.getShadowArray(0).getVal());
         if(ctFont.sizeOfStrikeArray() > 0) pr.addNewStrike().setVal(ctFont.getStrikeArray(0).getVal());
     }
-    
+
     /**
      * Does this string have any explicit formatting applied, or is 
      *  it just text in the default style?
      */
     public boolean hasFormatting() {
+        //noinspection deprecation - for performance reasons!
         CTRElt[] rs = st.getRArray();
         if (rs == null || rs.length == 0) {
             return false;
@@ -311,6 +312,7 @@ public class XSSFRichTextString implemen
             return utfDecode(st.getT());
         }
         StringBuilder buf = new StringBuilder();
+        //noinspection deprecation - for performance reasons!
         for(CTRElt r : st.getRArray()){
             buf.append(r.getT());
         }
@@ -381,6 +383,7 @@ public class XSSFRichTextString implemen
     public XSSFFont getFontAtIndex( int index ) {
         final ThemesTable themes = getThemesTable();
         int pos = 0;
+        //noinspection deprecation - for performance reasons!
         for(CTRElt r : st.getRArray()){
             final int length = r.getT().length();
             if(index >= pos && index < pos + length) {
@@ -406,6 +409,7 @@ public class XSSFRichTextString implemen
     protected void setStylesTableReference(StylesTable tbl){
         styles = tbl;
         if(st.sizeOfRArray() > 0) {
+            //noinspection deprecation - for performance reasons!
             for (CTRElt r : st.getRArray()) {
                 CTRPrElt pr = r.getRPr();
                 if(pr != null && pr.sizeOfRFontArray() > 0){
@@ -556,6 +560,7 @@ public class XSSFRichTextString implemen
     TreeMap<Integer, CTRPrElt> getFormatMap(CTRst entry){
         int length = 0;
         TreeMap<Integer, CTRPrElt> formats = new TreeMap<Integer, CTRPrElt>();
+        //noinspection deprecation - for performance reasons!
         for (CTRElt r : entry.getRArray()) {
             String txt = r.getT();
             CTRPrElt fmt = r.getRPr();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java?rev=1766065&r1=1766064&r2=1766065&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFRichTextString.java
Fri Oct 21 16:31:51 2016
@@ -229,13 +229,18 @@ public final class TestXSSFRichTextStrin
     /**
      * test that unicode representation_ xHHHH_ is properly processed
      */
-    public void testUtfDecode() {
+    public void testUtfDecode() throws IOException {
         CTRst st = CTRst.Factory.newInstance();
         st.setT("abc_x000D_2ef_x000D_");
         XSSFRichTextString rt = new XSSFRichTextString(st);
         //_x000D_ is converted into carriage return
         assertEquals("abc\r2ef\r", rt.getString());
-        
+
+        // Test Lowercase case
+        CTRst st2 = CTRst.Factory.newInstance();
+        st2.setT("abc_x000d_2ef_x000d_");
+        XSSFRichTextString rt2 = new XSSFRichTextString(st2);
+        assertEquals("abc\r2ef\r", rt2.getString());
     }
 
     public void testApplyFont_lowlevel(){
@@ -382,6 +387,7 @@ public final class TestXSSFRichTextStrin
     public void testLineBreaks_bug48877() throws IOException{
 
         XSSFFont font = new XSSFFont();
+        //noinspection deprecation
         font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
         font.setFontHeightInPoints((short) 14);
         XSSFRichTextString str;
@@ -423,8 +429,7 @@ public final class TestXSSFRichTextStrin
         str.applyFont(0, 4, font);
         t1 = str.getCTRst().getRArray(0).xgetT();
         t2 = str.getCTRst().getRArray(1).xgetT();
-        // YK: don't know why, but XmlBeans converts leading tab characters to spaces
-        //assertEquals("<xml-fragment>Tab\t</xml-fragment>", t1.xmlText());
+        assertEquals("<xml-fragment xml:space=\"preserve\">Tab\t</xml-fragment>",
t1.xmlText());
         assertEquals("<xml-fragment xml:space=\"preserve\">separated\n</xml-fragment>",
t2.xmlText());
 
         str = new XSSFRichTextString("\n\n\nNew Line\n\n");
@@ -439,8 +444,6 @@ public final class TestXSSFRichTextStrin
         assertEquals("<xml-fragment xml:space=\"preserve\">\n\n</xml-fragment>",
t3.xmlText());
     }
 
-    
-    @Test
     public void testBug56511() {
         XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56511.xlsx");
         for (Sheet sheet : wb) {
@@ -470,7 +473,6 @@ public final class TestXSSFRichTextStrin
         }
     }
 
-    @Test
     public void testBug56511_values() {
         XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56511.xlsx");
         Sheet sheet = wb.getSheetAt(0);
@@ -533,4 +535,10 @@ public final class TestXSSFRichTextStrin
         assertEquals(font, rts.getFontAtIndex(s2-1));
         assertEquals("<xml-fragment/>", rts.getFontAtIndex(s3-1).toString());
     }
+
+    public void test60289UtfDecode() throws IOException {
+        XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("60289.xlsx");
+        assertEquals("Rich Text\r\nTest", wb.getSheetAt(0).getRow(1).getCell(1).getRichStringCellValue().getString());
+        wb.close();
+    }
 }

Added: poi/trunk/test-data/spreadsheet/60289.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/60289.xlsx?rev=1766065&view=auto
==============================================================================
Binary files poi/trunk/test-data/spreadsheet/60289.xlsx (added) and poi/trunk/test-data/spreadsheet/60289.xlsx
Fri Oct 21 16:31:51 2016 differ



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


Mime
View raw message