mirror of https://github.com/aria2/aria2
Fixed base64::decode() return "" if input ends with garbase and no padding
parent
aa944f4ef6
commit
995c07c184
|
@ -133,7 +133,11 @@ std::string decode(InputIterator first, InputIterator last)
|
|||
for(int i = 1; i <= 4; ++i) {
|
||||
k[i] = getNext(first, last, INDEX_TABLE);
|
||||
if(k[i] == last) {
|
||||
res.clear();
|
||||
// If i == 1, input may look like this: "TWFu\n" (i.e.,
|
||||
// garbage at the end)
|
||||
if(i != 1) {
|
||||
res.clear();
|
||||
}
|
||||
return res;
|
||||
} else if(*k[i] == '=' && eq == 0) {
|
||||
eq = i;
|
||||
|
|
|
@ -76,6 +76,9 @@ void Base64Test::testDecode()
|
|||
s = "TWFu";
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("Man"), base64::decode(s.begin(), s.end()));
|
||||
|
||||
s = "TWFu\n";
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("Man"), base64::decode(s.begin(), s.end()));
|
||||
|
||||
s = "TQ==";
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("M"), base64::decode(s.begin(), s.end()));
|
||||
|
||||
|
|
Loading…
Reference in New Issue