@Test public void nonASCIIcharacter() throws Exception { assertEncoded("f","Zg=="); // A-grave assertEncoded("f","Zg=\u0100="); }
/** * This is NOT supported by Commons-Codec, see CODEC-121. * * @throws Exception * @see <a href="https://issues.apache.org/jira/browse/CODEC-121">CODEC-121</a> */ @Test public void softLineBreakDecode() throws Exception { assertEncoded("If you believe that truth=beauty, then surely mathematics is the most beautiful branch of philosophy.", "If you believe that truth=3Dbeauty, then surely=20=\r\nmathematics is the most beautiful branch of philosophy."); }
@Test public void decodeIso88591Base64Encoded() throws Exception { assertEncoded("If you can read this you understand the example.", "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n"); }
@Test(expected=UnsupportedEncodingException.class) public void decodeInvalidEncoding() throws Exception { MimeUtility.decodeText("=?invalid?B?xyz-?="); } }
@Test public void badPadding() throws Exception { assertIOException("incorrect padding, 4th byte", "Zg=a"); }
@Test public void invalidQuotedPrintableEncoding() throws Exception { assertIOException("truncated escape sequence", "YWJjMTIzXy0uKn4hQCMkJV4mKCkre31cIlxcOzpgLC9bXQ=="); }
@Test public void plainDecode() throws Exception { // spaces are allowed in encoded data // There are special rules for trailing spaces; these are not currently implemented. assertEncoded("The quick brown fox jumps over the lazy dog.", "The quick brown fox jumps over the lazy dog."); }
@Test public void decodeIso88591Base64EncodedWithWhiteSpace() throws Exception { assertEncoded("If you can read this you understand the example.", "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\t \r\n =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n"); }
@Test public void badLength() throws Exception { assertIOException("truncated", "Zm8=="); }
/** * Ignores non-BASE64 bytes. */ @Test public void nonBase64Bytes() throws Exception { assertEncoded("Hello World", "S?G!V%sbG 8g\rV\t\n29ybGQ*="); }
@Test public void invalidSoftBreak1() throws Exception { assertIOException("CR must be followed by LF", "=\r\r"); }
@Test public void emptyDecode() throws Exception { assertEncoded("", ""); }
@Test public void noNeedToDecode() throws Exception { assertEncoded("abc", "abc"); }
@Test public void badPaddingLeading1() throws Exception { assertIOException("incorrect padding, first two bytes cannot be padding", "=A=="); }
/** * Test our decode with pad character in the middle. * Continues provided that the padding is in the correct place, * i.e. concatenated valid strings decode OK. */ @Test public void decodeWithInnerPad() throws Exception { assertEncoded("Hello WorldHello World", "SGVsbG8gV29ybGQ=SGVsbG8gV29ybGQ="); }
@Test public void basicEncodeDecode() throws Exception { assertEncoded("= Hello there =\r\n", "=3D Hello there =3D=0D=0A"); }
@Test public void decodeUtf8QuotedPrintableEncoded() throws Exception { assertEncoded(" h! u !!!", "=?UTF-8?Q?_h=C3=A9!_=C3=A0=C3=A8=C3=B4u_!!!?="); }
@Test public void badPaddingLeading2() throws Exception { assertIOException("incorrect padding, first two bytes cannot be padding", "===="); }
@Test public void unsafeDecodeLowerCase() throws Exception { assertEncoded("=\r\n", "=3d=0d=0a"); }
@Test public void decodeUtf8Base64Encoded() throws Exception { assertEncoded(" h! u !!!", "=?UTF-8?B?IGjDqSEgw6DDqMO0dSAhISE=?="); }