diff options
author | Abseil Team <absl-team@google.com> | 2023-02-22 18:07:14 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-02-22 18:07:59 -0800 |
commit | c77bde682a4139ecf5c9bf97efe4f1104cd472f4 (patch) | |
tree | 476766a08d572dc8cf33e0463160e0ff81be2910 /absl/strings/escaping_test.cc | |
parent | 402e1319211cf19e455aa2a3b2de1f1235bb4326 (diff) |
Add CalculateBase64EscapeLen variations for the 3 base64 escaping methods (Base64Escape, WebSafeBase64Escape, WebSafeBase64EscapeWithPadding).
Also update CalculateBase64EscapedLen() documentation (it references outdated Base64Escape API), and reference it from WebSafeBase64Escape (to match Base64Escape).
PiperOrigin-RevId: 511647760
Change-Id: I7dee18645c2a779c0762bc71da75a4684ec2493f
Diffstat (limited to 'absl/strings/escaping_test.cc')
-rw-r--r-- | absl/strings/escaping_test.cc | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/absl/strings/escaping_test.cc b/absl/strings/escaping_test.cc index 44ffcba7..9f62c1ee 100644 --- a/absl/strings/escaping_test.cc +++ b/absl/strings/escaping_test.cc @@ -562,6 +562,7 @@ template <typename StringType> void TestEscapeAndUnescape() { // Check the short strings; this tests the math (and boundaries) for (const auto& tc : base64_tests) { + // Test plain base64. StringType encoded("this junk should be ignored"); absl::Base64Escape(tc.plaintext, &encoded); EXPECT_EQ(encoded, tc.cyphertext); @@ -571,22 +572,26 @@ void TestEscapeAndUnescape() { EXPECT_TRUE(absl::Base64Unescape(encoded, &decoded)); EXPECT_EQ(decoded, tc.plaintext); - StringType websafe(tc.cyphertext); - for (int c = 0; c < websafe.size(); ++c) { - if ('+' == websafe[c]) websafe[c] = '-'; - if ('/' == websafe[c]) websafe[c] = '_'; + StringType websafe_with_padding(tc.cyphertext); + for (unsigned int c = 0; c < websafe_with_padding.size(); ++c) { + if ('+' == websafe_with_padding[c]) websafe_with_padding[c] = '-'; + if ('/' == websafe_with_padding[c]) websafe_with_padding[c] = '_'; + // Intentionally keeping padding aka '='. + } + + // Test plain websafe (aka without padding). + StringType websafe(websafe_with_padding); + for (unsigned int c = 0; c < websafe.size(); ++c) { if ('=' == websafe[c]) { websafe.resize(c); break; } } - encoded = "this junk should be ignored"; absl::WebSafeBase64Escape(tc.plaintext, &encoded); EXPECT_EQ(encoded, websafe); EXPECT_EQ(absl::WebSafeBase64Escape(tc.plaintext), websafe); - // Let's try the string version of the decoder decoded = "this junk should be ignored"; EXPECT_TRUE(absl::WebSafeBase64Unescape(websafe, &decoded)); EXPECT_EQ(decoded, tc.plaintext); |