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

[mojo-stdlib] Fix base64 encode for non ASCII chars #2098

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/src/base64/base64.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn b64encode(str: String) -> String:
@parameter
@always_inline
fn s(idx: Int) -> Int:
return int(str._buffer[idx])
return int(str._as_ptr().bitcast[DType.uint8]()[idx])

# This algorithm is based on https://arxiv.org/abs/1704.00605
var end = length - (length % 3)
Expand Down
3 changes: 3 additions & 0 deletions stdlib/test/base64/test_base64.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ fn test_b64encode():
# CHECK: SGVsbG8gTW9qbyEhIQ==
print(b64encode("Hello Mojo!!!"))

# CHECK: SGVsbG8g8J+UpSEhIQ==
print(b64encode("Hello 🔥!!!"))

# CHECK: dGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==
print(b64encode("the quick brown fox jumps over the lazy dog"))

Expand Down
Loading