diff options
author | Abseil Team <absl-team@google.com> | 2022-10-21 15:42:10 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-10-21 15:42:43 -0700 |
commit | cb436cf0142b4cbe47aae94223443df7f82e2920 (patch) | |
tree | 24a1fc588b549a487e70c3075b78fc013263242b /absl/strings/escaping_test.cc | |
parent | 88eee8b5111230cd85c712e2cd465cae3ec84064 (diff) |
Document Base64Unescape() padding
PiperOrigin-RevId: 482905442
Change-Id: Ic3a1e62f8a17efee5508d94835635aa489940f2d
Diffstat (limited to 'absl/strings/escaping_test.cc')
-rw-r--r-- | absl/strings/escaping_test.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/absl/strings/escaping_test.cc b/absl/strings/escaping_test.cc index 45671a0e..44ffcba7 100644 --- a/absl/strings/escaping_test.cc +++ b/absl/strings/escaping_test.cc @@ -617,6 +617,48 @@ TEST(Base64, EscapeAndUnescape) { TestEscapeAndUnescape<std::string>(); } +TEST(Base64, Padding) { + // Padding is optional. + // '.' is an acceptable padding character, just like '='. + std::initializer_list<absl::string_view> good_padding = { + "YQ", + "YQ==", + "YQ=.", + "YQ.=", + "YQ..", + }; + for (absl::string_view b64 : good_padding) { + std::string decoded; + EXPECT_TRUE(absl::Base64Unescape(b64, &decoded)); + EXPECT_EQ(decoded, "a"); + std::string websafe_decoded; + EXPECT_TRUE(absl::WebSafeBase64Unescape(b64, &websafe_decoded)); + EXPECT_EQ(websafe_decoded, "a"); + } + std::initializer_list<absl::string_view> bad_padding = { + "YQ=", + "YQ.", + "YQ===", + "YQ==.", + "YQ=.=", + "YQ=..", + "YQ.==", + "YQ.=.", + "YQ..=", + "YQ...", + "YQ====", + "YQ....", + "YQ=====", + "YQ.....", + }; + for (absl::string_view b64 : bad_padding) { + std::string decoded; + EXPECT_FALSE(absl::Base64Unescape(b64, &decoded)); + std::string websafe_decoded; + EXPECT_FALSE(absl::WebSafeBase64Unescape(b64, &websafe_decoded)); + } +} + TEST(Base64, DISABLED_HugeData) { const size_t kSize = size_t(3) * 1000 * 1000 * 1000; static_assert(kSize % 3 == 0, "kSize must be divisible by 3"); |