From d712b6b2ad2e965dbbbbc625f89a83a79243ec74 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 16 Jul 2010 13:57:17 +0000 Subject: [PATCH] 49599 - Correct writing of NoteRecord author text when switching between ASCII and Unicode git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@964800 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../apache/poi/hssf/record/NoteRecord.java | 8 ++++++ .../poi/hssf/record/TestNoteRecord.java | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 122b33cc6b..21336b6ae7 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 49599 - Correct writing of NoteRecord author text when switching between ASCII and Unicode HWPF: Improve reading of auto-saved ("complex") documents Paragraph level as well as whole-file text extraction for Word 6/95 files through HWPF Text Extraction support for older Word 6 and Word 95 files via HWPF diff --git a/src/java/org/apache/poi/hssf/record/NoteRecord.java b/src/java/org/apache/poi/hssf/record/NoteRecord.java index 35f81ebfe7..86d4609606 100644 --- a/src/java/org/apache/poi/hssf/record/NoteRecord.java +++ b/src/java/org/apache/poi/hssf/record/NoteRecord.java @@ -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() { diff --git a/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java b/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java index 85776eacdd..c7e0dee3d1 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java @@ -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()); } } -- 2.39.5