diff options
author | Nick Burch <nick@apache.org> | 2010-07-16 13:57:17 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2010-07-16 13:57:17 +0000 |
commit | d712b6b2ad2e965dbbbbc625f89a83a79243ec74 (patch) | |
tree | ab282a9745960d3e4fe5a88ca2a2b4e2cf941d22 /src | |
parent | 9b6bf64760232c94149704572f16f1522eab6013 (diff) | |
download | poi-d712b6b2ad2e965dbbbbc625f89a83a79243ec74.tar.gz poi-d712b6b2ad2e965dbbbbc625f89a83a79243ec74.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/documentation/content/xdocs/status.xml | 1 | ||||
-rw-r--r-- | src/java/org/apache/poi/hssf/record/NoteRecord.java | 8 | ||||
-rw-r--r-- | src/testcases/org/apache/poi/hssf/record/TestNoteRecord.java | 26 |
3 files changed, 35 insertions, 0 deletions
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 @@ <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> 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()); } } |