poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1682999 - in /poi/trunk: src/java/org/apache/poi/hssf/record/ src/testcases/org/apache/poi/hssf/usermodel/ test-data/spreadsheet/
Date Mon, 01 Jun 2015 20:49:54 GMT
Author: centic
Date: Mon Jun  1 20:49:53 2015
New Revision: 1682999

URL: http://svn.apache.org/r1682999
Log:
Bug 53109: Correctly handle unicode strings in NameCommentRecord

Added:
    poi/trunk/test-data/spreadsheet/53109.xls
    poi/trunk/test-data/spreadsheet/com.aida-tour.www_SPO_files_maldives%20august%20october.xls
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/NameCommentRecord.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/NameCommentRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/NameCommentRecord.java?rev=1682999&r1=1682998&r2=1682999&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/NameCommentRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/NameCommentRecord.java Mon Jun  1 20:49:53
2015
@@ -62,17 +62,27 @@ public final class NameCommentRecord ext
     out.writeShort(field_4_name_length);
     out.writeShort(field_5_comment_length);
 
-    out.writeByte(0);
-    StringUtil.putCompressedUnicode(field_6_name_text, out);
-    out.writeByte(0);
-    StringUtil.putCompressedUnicode(field_7_comment_text, out);
+    boolean isNameMultiByte = StringUtil.hasMultibyte(field_6_name_text);
+    out.writeByte(isNameMultiByte ? 1 : 0);
+    if (isNameMultiByte) {
+        StringUtil.putUnicodeLE(field_6_name_text, out);
+    } else {
+        StringUtil.putCompressedUnicode(field_6_name_text, out);
+    }
+    boolean isCommentMultiByte = StringUtil.hasMultibyte(field_7_comment_text);
+    out.writeByte(isCommentMultiByte ? 1 : 0);
+    if (isCommentMultiByte) {
+        StringUtil.putUnicodeLE(field_7_comment_text, out);
+    } else {
+        StringUtil.putCompressedUnicode(field_7_comment_text, out);
+    }
   }
 
   @Override
   protected int getDataSize() {
     return 18 // 4 shorts + 1 long + 2 spurious 'nul's
-         + field_6_name_text.length()
-         + field_7_comment_text.length();
+         + (StringUtil.hasMultibyte(field_6_name_text) ? field_6_name_text.length()*2 : field_6_name_text.length())
+         + (StringUtil.hasMultibyte(field_7_comment_text) ? field_7_comment_text.length()*2
: field_7_comment_text.length());
   }
 
   /**
@@ -86,10 +96,16 @@ public final class NameCommentRecord ext
     final int field_4_name_length = in.readShort();
     final int field_5_comment_length = in.readShort();
 
-    in.readByte(); //spurious NUL
-    field_6_name_text = StringUtil.readCompressedUnicode(in, field_4_name_length);
-    in.readByte(); //spurious NUL
-    field_7_comment_text = StringUtil.readCompressedUnicode(in, field_5_comment_length);
+    if (in.readByte() == 0) {
+        field_6_name_text = StringUtil.readCompressedUnicode(in, field_4_name_length);
+    } else {
+        field_6_name_text = StringUtil.readUnicodeLE(in, field_4_name_length);
+    }
+    if (in.readByte() == 0) {
+        field_7_comment_text = StringUtil.readCompressedUnicode(in, field_5_comment_length);
+    } else {
+        field_7_comment_text = StringUtil.readUnicodeLE(in, field_5_comment_length);
+    }    
   }
 
   /**

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=1682999&r1=1682998&r2=1682999&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Mon Jun  1 20:49:53
2015
@@ -2738,4 +2738,24 @@ public final class TestBugs extends Base
         }
         wb.close();
     }
+
+    @Test
+    public void test53109() throws IOException {
+        HSSFWorkbook wb = openSample("53109.xls");
+        
+        Workbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        assertNotNull(wbBack);
+        
+        wb.close();
+    }
+    
+    @Test
+    public void test53109a() throws IOException {
+        HSSFWorkbook wb = openSample("com.aida-tour.www_SPO_files_maldives%20august%20october.xls");
+        
+        Workbook wbBack = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        assertNotNull(wbBack);
+        
+        wb.close();
+    }
 }

Added: poi/trunk/test-data/spreadsheet/53109.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/53109.xls?rev=1682999&view=auto
==============================================================================
Binary files poi/trunk/test-data/spreadsheet/53109.xls (added) and poi/trunk/test-data/spreadsheet/53109.xls
Mon Jun  1 20:49:53 2015 differ

Added: poi/trunk/test-data/spreadsheet/com.aida-tour.www_SPO_files_maldives%20august%20october.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/com.aida-tour.www_SPO_files_maldives%2520august%2520october.xls?rev=1682999&view=auto
==============================================================================
Binary files poi/trunk/test-data/spreadsheet/com.aida-tour.www_SPO_files_maldives%20august%20october.xls
(added) and poi/trunk/test-data/spreadsheet/com.aida-tour.www_SPO_files_maldives%20august%20october.xls
Mon Jun  1 20:49:53 2015 differ



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


Mime
View raw message