aboutsummaryrefslogtreecommitdiffstats
path: root/poi-scratchpad/src/test
diff options
context:
space:
mode:
authorTim Allison <tallison@apache.org>2023-09-20 20:32:59 +0000
committerTim Allison <tallison@apache.org>2023-09-20 20:32:59 +0000
commit99117381e59d9a7f2abe27784009358c672c0ae3 (patch)
tree190b7ef61d91f9579bd7605d1a2c45cf142ea674 /poi-scratchpad/src/test
parentce919673c4e935e8c756c91938f973d5c9a23ddb (diff)
downloadpoi-99117381e59d9a7f2abe27784009358c672c0ae3.tar.gz
poi-99117381e59d9a7f2abe27784009358c672c0ae3.zip
Bug47950 -- make stream/directory name lookup in OLE2 case insensitive
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912438 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-scratchpad/src/test')
-rw-r--r--poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java10
-rw-r--r--poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java4
-rw-r--r--poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestTextRunReWrite.java8
-rw-r--r--poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCurrentUserAtom.java2
-rw-r--r--poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjStg.java2
-rw-r--r--poi-scratchpad/src/test/java/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java46
-rw-r--r--poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFDocFixture.java4
-rw-r--r--poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java24
8 files changed, 57 insertions, 43 deletions
diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java
index 48e2666aa1..0606c28950 100644
--- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java
+++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java
@@ -92,20 +92,20 @@ public final class TestReWrite {
assertSlideShowWritesOutTheSame(hssC, pfsC);
// Currently has a Macros stream
- assertNotNull(pfsC.getRoot().getEntry("Macros"));
+ assertNotNull(pfsC.getRoot().getEntryCaseInsensitive("Macros"));
// Write out normally, will loose the macro stream
UnsynchronizedByteArrayOutputStream baos = UnsynchronizedByteArrayOutputStream.builder().get();
hssC.write(baos);
try (POIFSFileSystem pfsNew = new POIFSFileSystem(baos.toInputStream())) {
- assertFalse(pfsNew.getRoot().hasEntry("Macros"));
+ assertFalse(pfsNew.getRoot().hasEntryCaseInsensitive("Macros"));
}
// But if we write out with nodes preserved, will be there
baos.reset();
hssC.write(baos, true);
try (POIFSFileSystem pfsNew = new POIFSFileSystem(baos.toInputStream())) {
- assertTrue(pfsNew.getRoot().hasEntry("Macros"));
+ assertTrue(pfsNew.getRoot().hasEntryCaseInsensitive("Macros"));
}
}
}
@@ -145,8 +145,8 @@ public final class TestReWrite {
private void assertSame(POIFSFileSystem origPFS, POIFSFileSystem newPFS) throws IOException {
// Check that the "PowerPoint Document" sections have the same size
- DocumentEntry oProps = (DocumentEntry) origPFS.getRoot().getEntry(POWERPOINT_DOCUMENT);
- DocumentEntry nProps = (DocumentEntry) newPFS.getRoot().getEntry(POWERPOINT_DOCUMENT);
+ DocumentEntry oProps = (DocumentEntry) origPFS.getRoot().getEntryCaseInsensitive(POWERPOINT_DOCUMENT);
+ DocumentEntry nProps = (DocumentEntry) newPFS.getRoot().getEntryCaseInsensitive(POWERPOINT_DOCUMENT);
assertEquals(oProps.getSize(), nProps.getSize());
diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java
index 6b8a08ff2d..4d70257650 100644
--- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java
+++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java
@@ -185,8 +185,8 @@ public final class TestExtractor {
};
for (int i=0; i<TEST_SET.length; i+=2) {
- DirectoryNode dir = (DirectoryNode)root.getEntry(TEST_SET[i]);
- assertTrue(dir.hasEntry(HSLFSlideShow.POWERPOINT_DOCUMENT));
+ DirectoryNode dir = (DirectoryNode)root.getEntryCaseInsensitive(TEST_SET[i]);
+ assertTrue(dir.hasEntryCaseInsensitive(HSLFSlideShow.POWERPOINT_DOCUMENT));
try (final SlideShow<?,?> ppt = SlideShowFactory.create(dir);
final SlideShowExtractor<?,?> ppe = new SlideShowExtractor<>(ppt)) {
diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestTextRunReWrite.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestTextRunReWrite.java
index b38ae3ba51..658e2df370 100644
--- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestTextRunReWrite.java
+++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestTextRunReWrite.java
@@ -79,8 +79,8 @@ public final class TestTextRunReWrite {
// Check that the "PowerPoint Document" sections have the same size
DirectoryNode oDir = ppt1.getSlideShowImpl().getDirectory();
- DocumentEntry oProps = (DocumentEntry) oDir.getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
- DocumentEntry nProps = (DocumentEntry) npfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
+ DocumentEntry oProps = (DocumentEntry) oDir.getEntryCaseInsensitive(HSLFSlideShow.POWERPOINT_DOCUMENT);
+ DocumentEntry nProps = (DocumentEntry) npfs.getRoot().getEntryCaseInsensitive(HSLFSlideShow.POWERPOINT_DOCUMENT);
assertEquals(oProps.getSize(), nProps.getSize());
// Check that they contain the same data
@@ -130,8 +130,8 @@ public final class TestTextRunReWrite {
// Check that the "PowerPoint Document" sections have the same size
DirectoryNode oDir = ppt1.getSlideShowImpl().getDirectory();
- DocumentEntry oProps = (DocumentEntry) oDir.getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
- DocumentEntry nProps = (DocumentEntry) npfs.getRoot().getEntry(HSLFSlideShow.POWERPOINT_DOCUMENT);
+ DocumentEntry oProps = (DocumentEntry) oDir.getEntryCaseInsensitive(HSLFSlideShow.POWERPOINT_DOCUMENT);
+ DocumentEntry nProps = (DocumentEntry) npfs.getRoot().getEntryCaseInsensitive(HSLFSlideShow.POWERPOINT_DOCUMENT);
assertEquals(oProps.getSize(), nProps.getSize());
// Check that they contain the same data
diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCurrentUserAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCurrentUserAtom.java
index a1ee955fd3..780e36500a 100644
--- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCurrentUserAtom.java
+++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestCurrentUserAtom.java
@@ -76,7 +76,7 @@ public final class TestCurrentUserAtom {
// Get raw contents from a known file
byte[] contents;
try (POIFSFileSystem fs = new POIFSFileSystem(_slTests.getFile(normalFile))) {
- DocumentEntry docProps = (DocumentEntry) fs.getRoot().getEntry("Current User");
+ DocumentEntry docProps = (DocumentEntry) fs.getRoot().getEntryCaseInsensitive("Current User");
contents = new byte[docProps.getSize()];
try (InputStream in = fs.getRoot().createDocumentInputStream("Current User")) {
in.read(contents);
diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjStg.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjStg.java
index 46d607e729..8563bf7c5e 100644
--- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjStg.java
+++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjStg.java
@@ -62,7 +62,7 @@ public final class TestExOleObjStg {
assertEquals(len, oledata.length);
try (POIFSFileSystem fs = new POIFSFileSystem(record.getData())) {
- DocumentEntry doc = (DocumentEntry) fs.getRoot().getEntry("Contents");
+ DocumentEntry doc = (DocumentEntry) fs.getRoot().getEntryCaseInsensitive("Contents");
assertNotNull(doc);
}
}
diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java b/poi-scratchpad/src/test/java/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java
index f93ff19f0f..17d58effea 100644
--- a/poi-scratchpad/src/test/java/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java
+++ b/poi-scratchpad/src/test/java/org/apache/poi/hsmf/parsers/TestPOIFSChunkParser.java
@@ -56,13 +56,13 @@ public final class TestPOIFSChunkParser {
void testFindsCore() throws IOException, ChunkNotFoundException {
try (POIFSFileSystem simple = new POIFSFileSystem(samples.getFile("quick.msg"), true)) {
- // Check a few core things are present
- simple.getRoot().getEntry(
- (new StringChunk(MAPIProperty.SUBJECT.id, Types.ASCII_STRING)).getEntryName()
- );
- simple.getRoot().getEntry(
- (new StringChunk(MAPIProperty.SENDER_NAME.id, Types.ASCII_STRING)).getEntryName()
- );
+ // Check a few core things are present
+ simple.getRoot().getEntryCaseInsensitive(
+ (new StringChunk(MAPIProperty.SUBJECT.id, Types.ASCII_STRING)).getEntryName()
+ );
+ simple.getRoot().getEntryCaseInsensitive(
+ (new StringChunk(MAPIProperty.SENDER_NAME.id, Types.ASCII_STRING)).getEntryName()
+ );
// Now load the file
try (MAPIMessage msg = new MAPIMessage(simple)) {
@@ -82,7 +82,7 @@ public final class TestPOIFSChunkParser {
void testFindsRecips() throws IOException, ChunkNotFoundException {
try (POIFSFileSystem simple = new POIFSFileSystem(samples.getFile("quick.msg"), true)) {
- simple.getRoot().getEntry("__recip_version1.0_#00000000");
+ simple.getRoot().getEntryCaseInsensitive("__recip_version1.0_#00000000");
ChunkGroup[] groups = POIFSChunkParser.parse(simple.getRoot());
assertEquals(3, groups.length);
@@ -136,12 +136,12 @@ public final class TestPOIFSChunkParser {
void testFindsMultipleRecipients() throws IOException, ChunkNotFoundException {
try (POIFSFileSystem multiple = new POIFSFileSystem(samples.getFile("example_received_unicode.msg"), true)) {
- multiple.getRoot().getEntry("__recip_version1.0_#00000000");
- multiple.getRoot().getEntry("__recip_version1.0_#00000001");
- multiple.getRoot().getEntry("__recip_version1.0_#00000002");
- multiple.getRoot().getEntry("__recip_version1.0_#00000003");
- multiple.getRoot().getEntry("__recip_version1.0_#00000004");
- multiple.getRoot().getEntry("__recip_version1.0_#00000005");
+ multiple.getRoot().getEntryCaseInsensitive("__recip_version1.0_#00000000");
+ multiple.getRoot().getEntryCaseInsensitive("__recip_version1.0_#00000001");
+ multiple.getRoot().getEntryCaseInsensitive("__recip_version1.0_#00000002");
+ multiple.getRoot().getEntryCaseInsensitive("__recip_version1.0_#00000003");
+ multiple.getRoot().getEntryCaseInsensitive("__recip_version1.0_#00000004");
+ multiple.getRoot().getEntryCaseInsensitive("__recip_version1.0_#00000005");
ChunkGroup[] groups = POIFSChunkParser.parse(multiple.getRoot());
assertEquals(9, groups.length);
@@ -228,7 +228,7 @@ public final class TestPOIFSChunkParser {
void testFindsNameId() throws IOException {
try (POIFSFileSystem simple = new POIFSFileSystem(samples.getFile("quick.msg"), true)) {
- simple.getRoot().getEntry("__nameid_version1.0");
+ simple.getRoot().getEntryCaseInsensitive("__nameid_version1.0");
ChunkGroup[] groups = POIFSChunkParser.parse(simple.getRoot());
assertEquals(3, groups.length);
@@ -253,10 +253,11 @@ public final class TestPOIFSChunkParser {
POIFSFileSystem without = new POIFSFileSystem(samples.getFile("quick.msg"), true)) {
AttachmentChunks attachment;
- // Check raw details on the one with
- with.getRoot().getEntry("__attach_version1.0_#00000000");
- with.getRoot().getEntry("__attach_version1.0_#00000001");
- POIFSChunkParser.parse(with.getRoot());
+
+ // Check raw details on the one with
+ with.getRoot().getEntryCaseInsensitive("__attach_version1.0_#00000000");
+ with.getRoot().getEntryCaseInsensitive("__attach_version1.0_#00000001");
+ POIFSChunkParser.parse(with.getRoot());
ChunkGroup[] groups = POIFSChunkParser.parse(with.getRoot());
assertEquals(5, groups.length);
@@ -276,9 +277,10 @@ public final class TestPOIFSChunkParser {
assertEquals("pj1.txt", attachment.getAttachLongFileName().toString());
assertEquals(89, attachment.getAttachData().getValue().length);
- // Check raw details on one without
- assertFalse(without.getRoot().hasEntry("__attach_version1.0_#00000000"));
- assertFalse(without.getRoot().hasEntry("__attach_version1.0_#00000001"));
+
+ // Check raw details on one without
+ assertFalse(without.getRoot().hasEntryCaseInsensitive("__attach_version1.0_#00000000"));
+ assertFalse(without.getRoot().hasEntryCaseInsensitive("__attach_version1.0_#00000001"));
// One with, from the top
try (MAPIMessage msgWith = new MAPIMessage(with)) {
diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFDocFixture.java b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFDocFixture.java
index ea2a93cc12..54052acc58 100644
--- a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFDocFixture.java
+++ b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/HWPFDocFixture.java
@@ -44,7 +44,7 @@ public final class HWPFDocFixture
POIDataSamples.getDocumentInstance().openResourceAsStream(_testFile));
DocumentEntry documentProps =
- (DocumentEntry) filesystem.getRoot().getEntry("WordDocument");
+ (DocumentEntry) filesystem.getRoot().getEntryCaseInsensitive("WordDocument");
_mainStream = new byte[documentProps.getSize()];
filesystem.createDocumentInputStream("WordDocument").read(_mainStream);
@@ -59,7 +59,7 @@ public final class HWPFDocFixture
// read in the table stream.
DocumentEntry tableProps =
- (DocumentEntry) filesystem.getRoot().getEntry(name);
+ (DocumentEntry) filesystem.getRoot().getEntryCaseInsensitive(name);
_tableStream = new byte[tableProps.getSize()];
filesystem.createDocumentInputStream(name).read(_tableStream);
diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java
index 4ef67c44c8..a53fefd7fe 100644
--- a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java
+++ b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/extractor/TestWordExtractor.java
@@ -142,15 +142,15 @@ public final class TestWordExtractor {
POIFSFileSystem fs = new POIFSFileSystem(is);
is.close();
- DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B7");
- DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B2");
+ DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntryCaseInsensitive("MBD0000A3B7");
+ DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntryCaseInsensitive("MBD0000A3B2");
// Should have WordDocument and 1Table
- assertNotNull(dirA.getEntry("1Table"));
- assertNotNull(dirA.getEntry("WordDocument"));
+ assertNotNull(dirA.getEntryCaseInsensitive("1Table"));
+ assertNotNull(dirA.getEntryCaseInsensitive("WordDocument"));
- assertNotNull(dirB.getEntry("1Table"));
- assertNotNull(dirB.getEntry("WordDocument"));
+ assertNotNull(dirB.getEntryCaseInsensitive("1Table"));
+ assertNotNull(dirB.getEntryCaseInsensitive("WordDocument"));
// Check each in turn
HWPFDocument docA = new HWPFDocument(dirA);
@@ -403,6 +403,18 @@ public final class TestWordExtractor {
}
@Test
+ public void testCaseInsensitiveOLENames() throws Exception {
+ //test files are from Ross Johnson on TIKA-4091
+ for (String n : new String[]{"normal", "lower", "upper"}) {
+ try (InputStream is = docTests.openResourceAsStream("47950_" + n + ".doc");
+ POIFSFileSystem fs = new POIFSFileSystem(is);
+ WordExtractor wExt = new WordExtractor(fs)) {
+ assertContains(wExt.getText(), "This is a sample Word document");
+ }
+ }
+ }
+
+ @Test
void testCapitalized() throws Exception {
try (WordExtractor wExt = openExtractor("capitalized.doc")) {
String text = wExt.getText().trim();