Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[base64] Respect string encoding of input in base64_decode filters #1746

Merged
merged 2 commits into from
Sep 29, 2023

Conversation

gmalette
Copy link
Contributor

@gmalette gmalette commented Sep 29, 2023

Ruby's Base64.*decode64 functions return strings encoded in the Encoding::ASCII_8BIT scheme.

Ruby's string append has a special case if the string being appended is encoded over 7 bits, meaning that this works flawlessly:

decoded = @filters.base64_decode('Zm9v') # "foo" as base64
assert_equal("✅ foo", "✅ " + decoded)

However, for characters outside the 7 bit, such as most UTF-8 characters, this leads to a problem in which Ruby fails to concatenate the string, even if it's technically within a compatible domain.

decoded = @filters.base64_decode('4pyF') # "✅" as base64
assert_equal("✅ ✅", "✅ " + decoded)
#=> Minitest::UnexpectedError: Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT

To solve this problem and allow decoding emojis, I propose we attempt to change the encoding of the base64-decoded string, test if it's in the correct domain, and revert otherwise.

@gmalette gmalette merged commit 7b60b7f into main Sep 29, 2023
10 checks passed
@gmalette gmalette deleted the gm/base64-encoding branch September 29, 2023 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants