This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push: new a8969828 Add tests for IO-803 a8969828 is described below commit a8969828b82220502de785cdcec9bfc35861b048 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Wed Jun 14 09:05:24 2023 -0400 Add tests for IO-803 --- .../commons/io/input/ReaderInputStreamTest.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java b/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java index 944724e2..fb0636d4 100644 --- a/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java +++ b/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java @@ -36,12 +36,15 @@ import java.util.Random; import java.util.concurrent.TimeUnit; import java.util.stream.Stream; +import javax.xml.parsers.DocumentBuilderFactory; import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; public class ReaderInputStreamTest { @@ -199,6 +202,22 @@ public class ReaderInputStreamTest { } } + @Test + public void testIo803StringReaderSanityCheck() { + final StringReader reader = new StringReader(""); + final InputSource inputSource = new InputSource(reader); + assertThrows(SAXException.class, () -> DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputSource)); + } + + @Test + public void testIo803SAXException() throws IOException { + final StringReader reader = new StringReader(""); + try (final ReaderInputStream inputStream = ReaderInputStream.builder().setCharset(StandardCharsets.UTF_8).setReader(reader).get()) { + final InputSource inputSource = new InputSource(inputStream); + assertThrows(SAXException.class, () -> DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputSource)); + } + } + @Test public void testLargeUTF8WithBufferedRead() throws IOException { testWithBufferedRead(LARGE_TEST_STRING, UTF_8); @@ -231,6 +250,7 @@ public class ReaderInputStreamTest { testReadZero(inStr, inputStream); } } + private void testReadZero(final String inStr, final ReaderInputStream inputStream) throws IOException { final byte[] bytes = new byte[30]; assertEquals(0, inputStream.read(bytes, 0, 0));