Add support for the alternative base64 encoding in RFC 4648 section 5 to WhenBase64Unescaped.
				
					
				
			PiperOrigin-RevId: 507527786 Change-Id: Ie5e088b1814981f6c760d7e25418a430172705ec
This commit is contained in:
		
				
					committed by
					
						
						Copybara-Service
					
				
			
			
				
	
			
			
			
						parent
						
							2f2e72bae9
						
					
				
				
					commit
					3d568bdda5
				
			@@ -198,6 +198,10 @@ GTEST_API_ void IllegalDoDefault(const char* file, int line) {
 | 
			
		||||
      "the variable in various places.");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
constexpr char UndoWebSafeEncoding(char c) {
 | 
			
		||||
  return c == '-' ? '+' : c == '_' ? '/' : c;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
constexpr char UnBase64Impl(char c, const char* const base64, char carry) {
 | 
			
		||||
  return *base64 == 0 ? static_cast<char>(65)
 | 
			
		||||
         : *base64 == c
 | 
			
		||||
@@ -208,7 +212,8 @@ constexpr char UnBase64Impl(char c, const char* const base64, char carry) {
 | 
			
		||||
template <size_t... I>
 | 
			
		||||
constexpr std::array<char, 256> UnBase64Impl(IndexSequence<I...>,
 | 
			
		||||
                                             const char* const base64) {
 | 
			
		||||
  return {{UnBase64Impl(static_cast<char>(I), base64, 0)...}};
 | 
			
		||||
  return {
 | 
			
		||||
      {UnBase64Impl(UndoWebSafeEncoding(static_cast<char>(I)), base64, 0)...}};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
constexpr std::array<char, 256> UnBase64(const char* const base64) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1802,11 +1802,13 @@ TEST(WhenBase64UnescapedTest, MatchesUnescapedBase64Strings) {
 | 
			
		||||
  EXPECT_FALSE(m1.Matches("invalid base64"));
 | 
			
		||||
  EXPECT_FALSE(m1.Matches("aGVsbG8gd29ybGQ="));  // hello world
 | 
			
		||||
  EXPECT_TRUE(m1.Matches("aGVsbG8gd29ybGQh"));   // hello world!
 | 
			
		||||
  EXPECT_TRUE(m1.Matches("+/-_IQ"));             // \xfb\xff\xbf!
 | 
			
		||||
 | 
			
		||||
  const Matcher<const std::string&> m2 = WhenBase64Unescaped(EndsWith("!"));
 | 
			
		||||
  EXPECT_FALSE(m2.Matches("invalid base64"));
 | 
			
		||||
  EXPECT_FALSE(m2.Matches("aGVsbG8gd29ybGQ="));  // hello world
 | 
			
		||||
  EXPECT_TRUE(m2.Matches("aGVsbG8gd29ybGQh"));   // hello world!
 | 
			
		||||
  EXPECT_TRUE(m2.Matches("+/-_IQ"));             // \xfb\xff\xbf!
 | 
			
		||||
 | 
			
		||||
#if GTEST_INTERNAL_HAS_STRING_VIEW
 | 
			
		||||
  const Matcher<const internal::StringView&> m3 =
 | 
			
		||||
@@ -1814,6 +1816,7 @@ TEST(WhenBase64UnescapedTest, MatchesUnescapedBase64Strings) {
 | 
			
		||||
  EXPECT_FALSE(m3.Matches("invalid base64"));
 | 
			
		||||
  EXPECT_FALSE(m3.Matches("aGVsbG8gd29ybGQ="));  // hello world
 | 
			
		||||
  EXPECT_TRUE(m3.Matches("aGVsbG8gd29ybGQh"));   // hello world!
 | 
			
		||||
  EXPECT_TRUE(m3.Matches("+/-_IQ"));             // \xfb\xff\xbf!
 | 
			
		||||
#endif  // GTEST_INTERNAL_HAS_STRING_VIEW
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user