]> source.dussan.org Git - poi.git/commitdiff
49599 - Correct writing of NoteRecord author text when switching between ASCII and...
authorNick Burch <nick@apache.org>
Fri, 16 Jul 2010 13:57:17 +0000 (13:57 +0000)
committerNick Burch <nick@apache.org>
Fri, 16 Jul 2010 13:57:17 +0000 (13:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@964800 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/NoteRecord.java
src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java

index 122b33cc6bcd133f77c1470d2884651d82ebfbd0..21336b6ae7d65b9a93458766176613f2be4d98d5 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta2" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">49599 - Correct writing of NoteRecord author text when switching between ASCII and Unicode</action>
            <action dev="POI-DEVELOPERS" type="fix">HWPF: Improve reading of auto-saved ("complex") documents</action>
            <action dev="POI-DEVELOPERS" type="add">Paragraph level as well as whole-file text extraction for Word 6/95 files through HWPF</action>
            <action dev="POI-DEVELOPERS" type="add">Text Extraction support for older Word 6 and Word 95 files via HWPF</action>
index 35f81ebfe787dc1d2a60960c7e11429c817de0e9..86d4609606db0c790a97d8a6422eb3063314fb42 100644 (file)
@@ -190,6 +190,13 @@ public final class NoteRecord extends StandardRecord {
        public void setFlags(short flags) {
                field_3_flags = flags;
        }
+       
+       /**
+        * For unit testing only!
+        */
+       protected boolean authorIsMultibyte() {
+          return field_5_hasMultibyte;
+       }
 
        /**
         * Object id for OBJ record that contains the comment
@@ -221,6 +228,7 @@ public final class NoteRecord extends StandardRecord {
         */
        public void setAuthor(String author) {
                field_6_author = author;
+      field_5_hasMultibyte = StringUtil.hasMultibyte(author);
        }
 
        public Object clone() {
index 85776eacdd995f16113dad6213f9dea358360adc..c7e0dee3d1122fdb2cfdc540f26c8f1391502175 100644 (file)
@@ -102,8 +102,34 @@ public final class TestNoteRecord extends TestCase {
             throw new AssertionFailedError("Identified bug in reading note with unicode author");
         }
         assertEquals("\u30A2\u30D1\u30C3\u30C1\u65CF", nr.getAuthor());
+        assertTrue(nr.authorIsMultibyte());
         
         byte[] ser = nr.serialize();
         TestcaseRecordInputStream.confirmRecordEncoding(NoteRecord.sid, data, ser);
+
+        // Re-check
+        in = TestcaseRecordInputStream.create(ser);
+        nr = new NoteRecord(in);
+        assertEquals("\u30A2\u30D1\u30C3\u30C1\u65CF", nr.getAuthor());
+        assertTrue(nr.authorIsMultibyte());
+        
+        
+        // Change to a non unicode author, will stop being unicode
+        nr.setAuthor("Simple");
+        ser = nr.serialize();
+        in = TestcaseRecordInputStream.create(ser);
+        nr = new NoteRecord(in);
+        
+        assertEquals("Simple", nr.getAuthor());
+        assertFalse(nr.authorIsMultibyte());
+        
+        // Now set it back again
+        nr.setAuthor("Unicode\u1234");
+        ser = nr.serialize();
+        in = TestcaseRecordInputStream.create(ser);
+        nr = new NoteRecord(in);
+        
+        assertEquals("Unicode\u1234", nr.getAuthor());
+        assertTrue(nr.authorIsMultibyte());
     }
 }