Base64 decoding of strings always results in a Encoding::BINARY string result. Unfortunately, this means the contains operator will throw an Encoding::CompatibilityError whenever we attempt to compare the decoded result against a UTF8 string.
{% assign alphabet = "abcdef 🔤" | base64_encode | base64_decode %}
{% if alphabet contains "abc" %}
Next time won't you sing with me?
{% endif %}
If you don't know off the top of your head, you're in good company. Neither did I.
Next time won't you sing with me?
Obviously, throwing an internal error is not ideal. Instead, let's fallback to binary comparison of the string since that seems to me like the most "unsuprising" thing to do here.
Base64 decoding of strings always results in a
Encoding::BINARY
string result. Unfortunately, this means thecontains
operator will throw anEncoding::CompatibilityError
whenever we attempt to compare the decoded result against a UTF8 string.Today, the result of the above templates is:
But what about this template?
If you don't know off the top of your head, you're in good company. Neither did I.
Obviously, throwing an internal error is not ideal. Instead, let's fallback to binary comparison of the string since that seems to me like the most "unsuprising" thing to do here.