@@ -14,7 +14,7 @@ class SamlMessage
1414 ASSERTION = "urn:oasis:names:tc:SAML:2.0:assertion"
1515 PROTOCOL = "urn:oasis:names:tc:SAML:2.0:protocol"
1616
17- BASE64_FORMAT_REGEXP = %r{ \A (( [A-Za-z0-9+/]{4}))*( [A-Za-z0-9+/]{4} |[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==) \Z }
17+ BASE64_FORMAT = %r( \A [A-Za-z0-9+/]{4}* [A-Za-z0-9+/]{2}== |[A-Za-z0-9+/]{3}=? \Z )
1818
1919 def self . schema
2020 @schema ||= Mutex . new . synchronize do
@@ -48,7 +48,7 @@ def validation_error(message)
4848 # is to try and inflate it and fall back to the base64 decoded string if
4949 # the stream contains errors.
5050 def decode_raw_saml ( saml )
51- return saml unless base64_formatted ?( saml )
51+ return saml unless base64_encoded ?( saml )
5252
5353 decoded = decode ( saml )
5454 begin
@@ -72,11 +72,12 @@ def encode(encoded)
7272 Base64 . encode64 ( encoded ) . gsub ( /\n / , "" )
7373 end
7474
75- # Check if the provided string is base64 encoded.
76- # @param message [String] The value to be checked.
77- # @return [Boolean] True if the value is a base64 encoded string.
78- def base64_formatted? ( string )
79- string . gsub ( /[\r \n ]|\\ r|\\ n/ , "" ) . match ( BASE64_FORMAT_REGEXP )
75+ # Check if a string is base64 encoded
76+ #
77+ # @param string [String] string to check the encoding of
78+ # @return [true, false] whether or not the string is base64 encoded
79+ def base64_encoded? ( string )
80+ !!string . gsub ( /[\r \n ]|\\ r|\\ n/ , "" ) . match ( BASE64_FORMAT )
8081 end
8182
8283 def escape ( unescaped )
0 commit comments