am 629e18ad
: Fix base64 decoder. BUG 2081740.
Merge commit '629e18ad866917523599ed059898f4d986e49e26' into eclair * commit '629e18ad866917523599ed059898f4d986e49e26': Fix base64 decoder. BUG 2081740.
This commit is contained in:
commit
0967b74a62
@ -38,6 +38,7 @@ public class Base64InputStream extends InputStream {
|
||||
private int outIndex = 0;
|
||||
private final int[] outputBuffer = new int[3];
|
||||
private final byte[] inputBuffer = new byte[4];
|
||||
private boolean done = false;
|
||||
|
||||
public Base64InputStream(InputStream s) {
|
||||
this.s = s;
|
||||
@ -76,12 +77,15 @@ public class Base64InputStream extends InputStream {
|
||||
int inCount = 0;
|
||||
|
||||
int i;
|
||||
while (true) {
|
||||
// "done" is needed for the two successive '=' at the end
|
||||
while (!done) {
|
||||
switch (i = s.read()) {
|
||||
case -1:
|
||||
// No more input - just return, let outputBuffer drain out, and be done
|
||||
return;
|
||||
case '=':
|
||||
// once we meet the first '=', avoid reading the second '='
|
||||
done = true;
|
||||
decodeAndEnqueue(inCount);
|
||||
return;
|
||||
default:
|
||||
|
@ -18,6 +18,7 @@ package com.android.email.mail;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
import org.apache.james.mime4j.decoder.DecoderUtil;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@ -67,6 +68,27 @@ public class AddressUnitTests extends AndroidTestCase {
|
||||
mAddress3 = new Address("address3", null);
|
||||
}
|
||||
|
||||
// see documentation of DecoderUtil.decodeEncodedWords() for details
|
||||
private String padEncoded(String s) {
|
||||
return "=?UTF-8?B?" + s + "?=";
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate strings of incresing lenght by taking prefix substrings.
|
||||
* For each of them, compare with the decoding of the precomputed base-64 encoding.
|
||||
*/
|
||||
public void testBase64Decode() {
|
||||
String testString = "xyza\0\"";
|
||||
String base64Encoded[] = {"", "eA==", "eHk=", "eHl6", "eHl6YQ==", "eHl6YQA=", "eHl6YQAi"};
|
||||
int len = testString.length();
|
||||
for (int i = 1; i <= len; ++i) {
|
||||
String encoded = padEncoded(base64Encoded[i]);
|
||||
String decoded = DecoderUtil.decodeEncodedWords(encoded);
|
||||
String prefix = testString.substring(0, i);
|
||||
assertEquals(""+i, prefix, decoded);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for setAddress().
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user