# Tests are groups of three lines: program, input, expected output # Blank lines and lines starting with # are ignored @base64 "" "" @base64 "<>&'\"\t" "PD4mJyIJ" # decoding encoded output results in same text (@base64|@base64d) "<>&'\"\t" "<>&'\"\t" # regression test for #436 @base64 "foóbar\n" "Zm/Ds2Jhcgo=" @base64d "" "" @base64d "=" "" @base64d "Zm/Ds2Jhcgo=" "foóbar\n" # optional trailing equals padding (With padding, this is cWl4YmF6Cg==) @base64d "cWl4YmF6Cg" "qixbaz\n" # invalid base64 characters (whitespace) . | try @base64d catch . "Not base64 data" "string (\"Not base64 data\") is not valid base64 data" # invalid base64 (too many bytes, QUJD = "ABCD" . | try @base64d catch . "QUJDa" "string (\"QUJDa\") trailing base64 byte found" # padding is only allowed at the end of the input (#3730) . | try @base64d catch . "YWJjZA==ZWZn" "string (\"YWJjZA==ZWZn\") is not valid base64 data" . | try @base64d catch . "YW=Jj" "string (\"YW=Jj\") is not valid base64 data" . | try @base64d catch . "=YWJj" "string (\"=YWJj\") is not valid base64 data" . | try @base64d catch . "bW9ua2V5Cg== ZmlzaAo=" "string (\"bW9ua2V5Cg== ZmlzaAo=\") is not valid base64 data" # @base64 string interpolation encodes each value separately @base64 "\("a")\("bc")" | ., try @base64d catch . null "YQ==YmM=" "string (\"YQ==YmM=\") is not valid base64 data" # padded and unpadded input is still accepted map(@base64d) ["YWJjZA==", "YWJjZA", "YWJjZGU=", "YWJjZGU", "YWJjZGVm", "YQ==", "=="] ["abcd","abcd","abcde","abcde","abcdef","a",""]