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

Fix String/decode_utf8 returning a non-empty string when given an empty list #726

Merged
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
4 changes: 3 additions & 1 deletion src/fun/builtins.bend
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,9 @@ Utf8/REPLACEMENT_CHARACTER : u24 = '\u{FFFD}'

# Decodes a sequence of bytes to a String using utf-8 encoding.
# Invalid utf-8 sequences are replaced with Utf8/REPLACEMENT_CHARACTER.
String/decode_utf8 (bytes: (List u24)) : String =
String/decode_utf8 (bytes: (List u24)) : String
String/decode_utf8 [] = String/Nil
String/decode_utf8 bytes =
let (got, rest) = (Utf8/decode_character bytes)
match rest {
List/Nil: (String/Cons got String/Nil)
Expand Down
3 changes: 2 additions & 1 deletion tests/golden_tests/io/utf8.bend
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ v2 = (to-and-back "(λf ((λx (f (x x))) (λx (f (x x)))))")
v3 = (to-and-back "🌟")
v4 = (to-and-back "Hello 🌎!")
v5 = (to-and-back "𓆈 𓆉 𓆊 𓆋 𓅯")
v6 = (String/decode_utf8 [])

main = [v1, v2, v3, v4, v5]
main = [v1, v2, v3, v4, v5, v6]
2 changes: 1 addition & 1 deletion tests/snapshots/io__utf8.bend.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ source: tests/golden_tests.rs
input_file: tests/golden_tests/io/utf8.bend
---
Strict mode:
["hi", "(λf ((λx (f (x x))) (λx (f (x x)))))", "🌟", "Hello 🌎!", "𓆈 𓆉 𓆊 𓆋 𓅯"]
["hi", "(λf ((λx (f (x x))) (λx (f (x x)))))", "🌟", "Hello 🌎!", "𓆈 𓆉 𓆊 𓆋 𓅯", ""]
Loading