aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2008-12-09 19:36:53 +0000
committerNick Burch <nick@apache.org>2008-12-09 19:36:53 +0000
commiteca181f8e46ba93045f2ea0306a6623833d4d2cd (patch)
tree069ff7feb68e493bd5f3f29ea199245864e70ee7
parent7e6c4c3de8f02a6a2f486fddf8cbb509dbd25c2c (diff)
downloadpoi-eca181f8e46ba93045f2ea0306a6623833d4d2cd.tar.gz
poi-eca181f8e46ba93045f2ea0306a6623833d4d2cd.zip
Fix bug #46368 - HSSFRichTextRun and strings longer than 32768 characters
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@724848 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/documentation/content/xdocs/changes.xml1
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/hssf/record/UnicodeString.java24
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java3
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java35
5 files changed, 55 insertions, 9 deletions
diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml
index 871d80e0f6..8af6deb5a8 100644
--- a/src/documentation/content/xdocs/changes.xml
+++ b/src/documentation/content/xdocs/changes.xml
@@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.5-beta5" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">46368 - Fix HSSFRichTextRun and strings longer than 32768 characters</action>
<action dev="POI-DEVELOPERS" type="add">Support sheet-level names</action>
<action dev="POI-DEVELOPERS" type="fix">Fixed XSSFCell to properly handle cell references with column numbers up to XFD</action>
<action dev="POI-DEVELOPERS" type="fix">44914 - Fixed warning message "WARN. Unread n bytes of record 0xNN"</action>
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 8d09549af9..d939d90113 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.5-beta5" date="2008-??-??">
+ <action dev="POI-DEVELOPERS" type="fix">46368 - Fix HSSFRichTextRun and strings longer than 32768 characters</action>
<action dev="POI-DEVELOPERS" type="add">Support sheet-level names</action>
<action dev="POI-DEVELOPERS" type="fix">Fixed XSSFCell to properly handle cell references with column numbers up to XFD</action>
<action dev="POI-DEVELOPERS" type="fix">44914 - Fixed warning message "WARN. Unread n bytes of record 0xNN"</action>
diff --git a/src/java/org/apache/poi/hssf/record/UnicodeString.java b/src/java/org/apache/poi/hssf/record/UnicodeString.java
index fc493d4348..a47cd05986 100644
--- a/src/java/org/apache/poi/hssf/record/UnicodeString.java
+++ b/src/java/org/apache/poi/hssf/record/UnicodeString.java
@@ -202,9 +202,9 @@ public final class UnicodeString implements Comparable {
boolean isCompressed = ((field_2_optionflags & 1) == 0);
if (isCompressed) {
- field_3_string = in.readCompressedUnicode(field_1_charCount);
+ field_3_string = in.readCompressedUnicode(getCharCount());
} else {
- field_3_string = in.readUnicodeLEString(field_1_charCount);
+ field_3_string = in.readUnicodeLEString(getCharCount());
}
@@ -226,15 +226,25 @@ public final class UnicodeString implements Comparable {
/**
- * get the number of characters in the string
- *
+ * get the number of characters in the string,
+ * as an un-wrapped int
*
* @return number of characters
- *
*/
+ public int getCharCount() {
+ if(field_1_charCount < 0) {
+ return field_1_charCount + 65536;
+ }
+ return field_1_charCount;
+ }
- public short getCharCount()
- {
+ /**
+ * get the number of characters in the string,
+ * wrapped as needed to fit within a short
+ *
+ * @return number of characters
+ */
+ public short getCharCountShort() {
return field_1_charCount;
}
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java b/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java
index 9d57c99a43..35f91eaef5 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFRichTextString.java
@@ -198,8 +198,7 @@ public class HSSFRichTextString
/**
* @return the number of characters in the text.
*/
- public int length()
- {
+ public int length() {
return string.getCharCount();
}
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index 2c28be6501..1766199e45 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -35,6 +35,9 @@ import org.apache.poi.hssf.record.NameRecord;
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
import org.apache.poi.hssf.record.formula.Ptg;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.RichTextString;
+import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.TempFile;
@@ -1540,4 +1543,36 @@ public final class TestBugs extends TestCase {
HSSFWorkbook wb = openSample("45290.xls");
assertEquals(1, wb.getNumberOfSheets());
}
+
+ /**
+ * HSSFRichTextString.length() returns negative for really
+ * long strings
+ */
+ public void test46368() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet s = wb.createSheet();
+ HSSFRow r = s.createRow(0);
+ for(int i=0; i<15; i++) {
+ int len = 32760 + i;
+ HSSFCell c = r.createCell(i);
+
+ StringBuffer sb = new StringBuffer();
+ for(int j=0; j<len; j++) {
+ sb.append("x");
+ }
+ HSSFRichTextString rtr = new HSSFRichTextString(sb.toString());
+ assertEquals(len, rtr.length());
+ c.setCellValue(rtr);
+ }
+
+ // Save and reload
+ wb = writeOutAndReadBack(wb);
+ s = wb.getSheetAt(0);
+ r = s.getRow(0);
+ for(int i=0; i<15; i++) {
+ int len = 32760 + i;
+ HSSFCell c = r.getCell(i);
+ assertEquals(len, c.getRichStringCellValue().length());
+ }
+ }
}