Skip to content

Commit

Permalink
Bug 58805: Adjust reproducer test-case some more
Browse files Browse the repository at this point in the history
Do not write a local temp-file
It seems even parsing the resulting document fails

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1923063 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
centic9 committed Jan 11, 2025
1 parent 43a15ff commit 86c0db4
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
Expand All @@ -37,6 +37,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import java.util.List;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.extractor.POITextExtractor;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFOldDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
Expand Down Expand Up @@ -798,9 +800,14 @@ void test58805() throws IOException {
run.replaceText("_TEST_", "This text is longer than the initial text. It goes on and on without interruption.");
}

try (FileOutputStream fos = new FileOutputStream(new File("/tmp/test.doc"))) {
doc.write(fos);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
doc.write(out);
out.flush();

POITextExtractor extractor = ExtractorFactory.createExtractor(new ByteArrayInputStream(out.toByteArray()));
assertThrows(IllegalArgumentException.class,
() -> /*String text =*/ extractor.getText());
// assertFalse(text.contains("_TEST_"), "Had: " + text);
}
}
}

0 comments on commit 86c0db4

Please sign in to comment.