diff options
author | PJ Fanning <fanningpj@apache.org> | 2022-12-12 18:43:44 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2022-12-12 18:43:44 +0000 |
commit | 5a6df66b07ba527bc4195a604b446af807087c66 (patch) | |
tree | 5cb69e7dd40d70f99d7dff49a055cdfe93c8d1eb | |
parent | fdffe5f66d1c4c09b1edf77f009c3950f60b9ed0 (diff) | |
download | poi-5a6df66b07ba527bc4195a604b446af807087c66.tar.gz poi-5a6df66b07ba527bc4195a604b446af807087c66.zip |
untidy hack for shared string counts that are higher than Integer.MAX_VALUE
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1905940 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java | 28 | ||||
-rw-r--r-- | test-data/spreadsheet/MalformedSSTCount.xlsx | bin | 0 -> 6266 bytes |
2 files changed, 26 insertions, 2 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java index 992dc32113..7df35d713c 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/eventusermodel/TestReadOnlySharedStringsTable.java @@ -69,11 +69,35 @@ public final class TestReadOnlySharedStringsTable { } } + @Test + void testParseMalformedCountFile() throws Exception { + try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("MalformedSSTCount.xlsx"))) { + List<PackagePart> parts = pkg.getPartsByName(Pattern.compile("/xl/sharedStrings.xml")); + assertEquals(1, parts.size()); + + SharedStringsTable stbl = new SharedStringsTable(parts.get(0)); + ReadOnlySharedStringsTable rtbl = new ReadOnlySharedStringsTable(parts.get(0)); + ReadOnlySharedStringsTable rtbl2; + try (InputStream stream = parts.get(0).getInputStream()) { + rtbl2 = new ReadOnlySharedStringsTable(stream); + } + + assertEquals(stbl.getCount(), rtbl.getCount()); + assertEquals(stbl.getUniqueCount(), rtbl.getUniqueCount()); + assertEquals(stbl.getUniqueCount(), rtbl2.getUniqueCount()); + for (int i = 0; i < stbl.getUniqueCount(); i++) { + RichTextString i1 = stbl.getItemAt(i); + assertEquals(i1.getString(), rtbl.getItemAt(i).getString()); + assertEquals(i1.getString(), rtbl2.getItemAt(i).getString()); + } + } + } + //51519 @Test void testPhoneticRuns() throws Exception { try (OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("51519.xlsx"))) { - List < PackagePart > parts = pkg.getPartsByName(Pattern.compile("/xl/sharedStrings.xml")); + List<PackagePart> parts = pkg.getPartsByName(Pattern.compile("/xl/sharedStrings.xml")); assertEquals(1, parts.size()); ReadOnlySharedStringsTable rtbl = new ReadOnlySharedStringsTable(parts.get(0), true); @@ -83,7 +107,7 @@ public final class TestReadOnlySharedStringsTable { assertEquals("\u65E5\u672C\u30AA\u30E9\u30AF\u30EB \u30CB\u30DB\u30F3", rtbl.getItemAt(3).getString()); //now do not include phonetic runs - rtbl = new ReadOnlySharedStringsTable(parts.get(0),false); + rtbl = new ReadOnlySharedStringsTable(parts.get(0), false); assertEquals(49, rtbl.getUniqueCount()); assertEquals("\u30B3\u30E1\u30F3\u30C8", rtbl.getItemAt(0).getString()); diff --git a/test-data/spreadsheet/MalformedSSTCount.xlsx b/test-data/spreadsheet/MalformedSSTCount.xlsx Binary files differnew file mode 100644 index 0000000000..6c955fa684 --- /dev/null +++ b/test-data/spreadsheet/MalformedSSTCount.xlsx |