-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix from_base64 Presto function for inputs without padding (#8647)
Summary: Fixes #8646 Pull Request resolved: #8647 Reviewed By: amitkdutta, DanielMunozT Differential Revision: D56792399 Pulled By: bikramSingh91 fbshipit-source-id: 212acce56c0dd708e1220e229e1943380d4d976b
- Loading branch information
1 parent
5bf1e27
commit b7bacaf
Showing
8 changed files
with
197 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "velox/common/encode/Base64.h" | ||
#include <gtest/gtest.h> | ||
#include "velox/common/base/tests/GTestUtils.h" | ||
|
||
namespace facebook::velox::encoding { | ||
class Base64Test : public ::testing::Test {}; | ||
|
||
TEST_F(Base64Test, fromBase64) { | ||
EXPECT_EQ( | ||
"Hello, World!", | ||
Base64::decode(folly::StringPiece("SGVsbG8sIFdvcmxkIQ=="))); | ||
EXPECT_EQ( | ||
"Base64 encoding is fun.", | ||
Base64::decode(folly::StringPiece("QmFzZTY0IGVuY29kaW5nIGlzIGZ1bi4="))); | ||
EXPECT_EQ( | ||
"Simple text", Base64::decode(folly::StringPiece("U2ltcGxlIHRleHQ="))); | ||
EXPECT_EQ( | ||
"1234567890", Base64::decode(folly::StringPiece("MTIzNDU2Nzg5MA=="))); | ||
|
||
// Check encoded strings without padding | ||
EXPECT_EQ( | ||
"Hello, World!", | ||
Base64::decode(folly::StringPiece("SGVsbG8sIFdvcmxkIQ"))); | ||
EXPECT_EQ( | ||
"Base64 encoding is fun.", | ||
Base64::decode(folly::StringPiece("QmFzZTY0IGVuY29kaW5nIGlzIGZ1bi4"))); | ||
EXPECT_EQ( | ||
"Simple text", Base64::decode(folly::StringPiece("U2ltcGxlIHRleHQ"))); | ||
EXPECT_EQ("1234567890", Base64::decode(folly::StringPiece("MTIzNDU2Nzg5MA"))); | ||
} | ||
|
||
TEST_F(Base64Test, calculateDecodedSizeProperSize) { | ||
size_t encoded_size{0}; | ||
|
||
encoded_size = 20; | ||
EXPECT_EQ( | ||
13, Base64::calculateDecodedSize("SGVsbG8sIFdvcmxkIQ==", encoded_size)); | ||
EXPECT_EQ(18, encoded_size); | ||
|
||
encoded_size = 18; | ||
EXPECT_EQ( | ||
13, Base64::calculateDecodedSize("SGVsbG8sIFdvcmxkIQ", encoded_size)); | ||
EXPECT_EQ(18, encoded_size); | ||
|
||
encoded_size = 21; | ||
EXPECT_THROW( | ||
Base64::calculateDecodedSize("SGVsbG8sIFdvcmxkIQ==", encoded_size), | ||
facebook::velox::encoding::Base64Exception); | ||
|
||
encoded_size = 32; | ||
EXPECT_EQ( | ||
23, | ||
Base64::calculateDecodedSize( | ||
"QmFzZTY0IGVuY29kaW5nIGlzIGZ1bi4=", encoded_size)); | ||
EXPECT_EQ(31, encoded_size); | ||
|
||
encoded_size = 31; | ||
EXPECT_EQ( | ||
23, | ||
Base64::calculateDecodedSize( | ||
"QmFzZTY0IGVuY29kaW5nIGlzIGZ1bi4", encoded_size)); | ||
EXPECT_EQ(31, encoded_size); | ||
|
||
encoded_size = 16; | ||
EXPECT_EQ(10, Base64::calculateDecodedSize("MTIzNDU2Nzg5MA==", encoded_size)); | ||
EXPECT_EQ(14, encoded_size); | ||
|
||
encoded_size = 14; | ||
EXPECT_EQ(10, Base64::calculateDecodedSize("MTIzNDU2Nzg5MA", encoded_size)); | ||
EXPECT_EQ(14, encoded_size); | ||
} | ||
|
||
} // namespace facebook::velox::encoding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
add_executable(velox_common_encode_test Base64Test.cpp) | ||
add_test(velox_common_encode_test velox_common_encode_test) | ||
target_link_libraries( | ||
velox_common_encode_test | ||
PUBLIC Folly::folly | ||
PRIVATE velox_encode velox_exception gtest gtest_main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.