Author: sebb Date: Tue Mar 19 19:55:12 2013 New Revision: 1458483 URL: http://svn.apache.org/r1458483 Log: Test some error conditions
Modified: commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java Modified: commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java?rev=1458483&r1=1458482&r2=1458483&view=diff ============================================================================== --- commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java (original) +++ commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java Tue Mar 19 19:55:12 2013 @@ -17,9 +17,12 @@ package org.apache.commons.fileupload.util.mime; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.fail; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.io.UnsupportedEncodingException; import org.junit.Test; @@ -57,6 +60,21 @@ public final class QuotedPrintableDecode "If you believe that truth=3Dbeauty, then surely=20=\r\nmathematics is the most beautiful branch of philosophy."); } + @Test + public void invalidSoftBreak1() throws Exception { + assertIOException("CR must be followed by LF", "=\r\r"); + } + + @Test + public void invalidSoftBreak2() throws Exception { + assertIOException("CR must be followed by LF", "=\rn"); + } + + @Test + public void truncatedEscape() throws Exception { + assertIOException("truncated", "=1"); + } + private static void assertEncoded(String clearText, String encoded) throws Exception { byte[] expected = clearText.getBytes(US_ASCII_CHARSET); @@ -68,4 +86,16 @@ public final class QuotedPrintableDecode assertArrayEquals(expected, actual); } + private static void assertIOException(String messageText, String encoded) throws UnsupportedEncodingException { + ByteArrayOutputStream out = new ByteArrayOutputStream(encoded.length()); + byte[] encodedData = encoded.getBytes(US_ASCII_CHARSET); + try { + QuotedPrintableDecoder.decode(encodedData, out); + fail("Expected IOException"); + } catch (IOException e) { + String em = e.getMessage(); + assertTrue("Expected to find " + messageText + " in '" + em + "'",em.contains(messageText)); } + + } + }