diff --git a/conformance/BUILD.bazel b/conformance/BUILD.bazel index 85b6aa13..df990e88 100644 --- a/conformance/BUILD.bazel +++ b/conformance/BUILD.bazel @@ -47,9 +47,6 @@ _TESTS_TO_SKIP = [ "macros/map/map_extract_keys", "timestamps/duration_converters/get_milliseconds", - # Failing conformance test for unknown reasons - "encoders_ext/decode/hello_without_padding", - # Future enhancments. "enums/strong_proto2", "enums/strong_proto3", diff --git a/ext/encoders.go b/ext/encoders.go index 61ac0b77..ac04b1a7 100644 --- a/ext/encoders.go +++ b/ext/encoders.go @@ -36,7 +36,7 @@ import ( // Examples: // // base64.decode('aGVsbG8=') // return b'hello' -// base64.decode('aGVsbG8') // error +// base64.decode('aGVsbG8') // return b'hello' // // # Base64.Encode // @@ -79,7 +79,14 @@ func (encoderLib) ProgramOptions() []cel.ProgramOption { } func base64DecodeString(str string) ([]byte, error) { - return base64.StdEncoding.DecodeString(str) + b, err := base64.StdEncoding.DecodeString(str) + if err == nil { + return b, nil + } + if _, tryAltEncoding := err.(base64.CorruptInputError); tryAltEncoding { + return base64.RawStdEncoding.DecodeString(str) + } + return nil, err } func base64EncodeBytes(bytes []byte) (string, error) { diff --git a/ext/encoders_test.go b/ext/encoders_test.go index 05580192..959cb837 100644 --- a/ext/encoders_test.go +++ b/ext/encoders_test.go @@ -29,10 +29,7 @@ func TestEncoders(t *testing.T) { parseOnly bool }{ {expr: "base64.decode('aGVsbG8=') == b'hello'"}, - { - expr: "base64.decode('aGVsbG8') == b'error'", - err: "illegal base64 data at input byte 4", - }, + {expr: "base64.decode('aGVsbG8') == b'hello'"}, { expr: "base64.decode(b'aGVsbG8=') == b'hello'", err: "no such overload",