Skip to content

Commit 869aff1

Browse files
committed
Fix crash with unmodified bit builder
1 parent cd9f783 commit 869aff1

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/gleam/bit_builder.gleam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub external fn concat(List(BitBuilder)) -> BitBuilder =
7474
/// Runs in constant time.
7575
///
7676
pub external fn from_bit_string(BitString) -> BitBuilder =
77-
"gleam_stdlib" "identity"
77+
"gleam_stdlib" "wrap_list"
7878

7979
/// Turns an builder into a bit string.
8080
///

src/gleam_stdlib.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
string_pad/4, decode_tuple2/1, decode_map/1, bit_string_int_to_u32/1,
1212
bit_string_int_from_u32/1, bit_string_append/2, bit_string_part_/3,
1313
decode_bit_string/1, compile_regex/2, regex_match/2, regex_split/2,
14-
regex_scan/2, base_decoded4/1]).
14+
regex_scan/2, base_decoded4/1, wrap_list/1]).
1515

1616
should_equal(Actual, Expected) -> ?assertEqual(Expected, Actual).
1717
should_not_equal(Actual, Expected) -> ?assertNotEqual(Expected, Actual).
@@ -205,3 +205,6 @@ base_decoded4(S) ->
205205
try {ok, base64:decode(S)}
206206
catch error:badarith -> {error, nil}
207207
end.
208+
209+
wrap_list(X) when is_list(X) -> X;
210+
wrap_list(X) -> [X].

test/gleam/bit_string_builder_test.gleam renamed to test/gleam/bit_builder_test.gleam

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,10 @@ pub fn concat_test() {
5656
|> bit_builder.to_bit_string
5757
|> should.equal(<<1, 2, 3, 4, 5, 6>>)
5858
}
59+
60+
pub fn from_string_test() {
61+
// Regression test: no additional modification of the builder
62+
bit_builder.from_bit_string(<<>>)
63+
|> bit_builder.to_bit_string
64+
|> should.equal(<<>>)
65+
}

0 commit comments

Comments
 (0)