Skip to content

Commit

Permalink
Fix String/decode_utf8 returning a non-empty string when given an e…
Browse files Browse the repository at this point in the history
…mpty list (#726)
  • Loading branch information
chalcolith authored Oct 9, 2024
1 parent 7080bbe commit 9da1f49
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
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 🌎!", "𓆈 𓆉 𓆊 𓆋 𓅯", ""]

0 comments on commit 9da1f49

Please sign in to comment.