Skip to content

Commit

Permalink
GH-1461 Do not add or expect = at end of base64 encoded strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Aug 8, 2023
1 parent 47db353 commit 5c2f507
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions libraries/libfc/src/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ std::string variant::as_string()const
return *reinterpret_cast<const bool*>(this) ? "true" : "false";
case blob_type:
if( get_blob().data.size() )
return base64_encode( get_blob().data.data(), get_blob().data.size() ) + "=";
return base64_encode( get_blob().data.data(), get_blob().data.size() );
return std::string();
case null_type:
return std::string();
Expand Down Expand Up @@ -533,10 +533,11 @@ blob variant::as_blob()const
{
const std::string& str = get_string();
if( str.size() == 0 ) return blob();
if( str.back() == '=' )
{
try {
std::string b64 = base64_decode( get_string() );
return blob( { std::vector<char>( b64.begin(), b64.end() ) } );
} catch(const std::exception&) {
// unable to decode, just return the raw chars
}
return blob( { std::vector<char>( str.begin(), str.end() ) } );
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/libfc/test/variant/test_variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE(variant_format_string_limited)
const string target_result = format_prefix + a_short_list + " " +
"{" + "\"b\":\"" + b_short_list + "\",\"c\":\"" + c_short_list + "\"}" + " " +
"[\"" + d_short_list + "\",\"" + e_short_list + "\"]" + " " +
base64_encode( a_blob.data.data(), a_blob.data.size() ) + "=" + " " +
base64_encode( a_blob.data.data(), a_blob.data.size() ) + " " +
g_short_list;

BOOST_CHECK_EQUAL( result, target_result);
Expand Down

0 comments on commit 5c2f507

Please sign in to comment.