diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5b6c90a..6c6c6c9 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,8 @@ +4.0.1 +----- + +* Fixed a call stack error on the JavaScript target + 4.0.0 ----- diff --git a/gleam.toml b/gleam.toml index 685f36f..18add32 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,5 +1,5 @@ name = "glentities" -version = "4.0.0" +version = "4.0.1" description = "HTML entity encoder/decoder for Gleam" # Fill out these fields if you intend to generate HTML documentation or publish diff --git a/src/glentities.gleam b/src/glentities.gleam index b97e2c2..76a6649 100644 --- a/src/glentities.gleam +++ b/src/glentities.gleam @@ -2332,7 +2332,14 @@ pub fn encode_html_body(text: String, acc: StringBuilder) -> String { ">" <> rest -> encode_html_body(rest, string_builder.append(acc, ">")) "\"" <> rest -> encode_html_body(rest, string_builder.append(acc, """)) "'" <> rest -> encode_html_body(rest, string_builder.append(acc, "'")) - other -> encode_other_case(other, acc, encode_html_body) + other -> { + let maybe_grapheme = string.pop_grapheme(other) + case maybe_grapheme { + Ok(#(grapheme, rest)) -> + encode_html_body(rest, string_builder.append(acc, grapheme)) + Error(Nil) -> string_builder.to_string(acc) + } + } } } @@ -4074,19 +4081,13 @@ pub fn encode_named(text: String, acc: StringBuilder) -> String { "𝓏" <> rest -> encode_named(rest, string_builder.append(acc, "𝓏")) "‍" <> rest -> encode_named(rest, string_builder.append(acc, "‍")) "‌" <> rest -> encode_named(rest, string_builder.append(acc, "‌")) - other -> encode_other_case(other, acc, encode_named) - } -} - -fn encode_other_case( - text: String, - acc: StringBuilder, - continue_callback: fn(String, StringBuilder) -> String, -) -> String { - let maybe_grapheme = string.pop_grapheme(text) - case maybe_grapheme { - Ok(#(grapheme, rest)) -> - continue_callback(rest, string_builder.append(acc, grapheme)) - Error(Nil) -> string_builder.to_string(acc) + other -> { + let maybe_grapheme = string.pop_grapheme(other) + case maybe_grapheme { + Ok(#(grapheme, rest)) -> + encode_named(rest, string_builder.append(acc, grapheme)) + Error(Nil) -> string_builder.to_string(acc) + } + } } } diff --git a/test/glentities_test.gleam b/test/glentities_test.gleam index 852a629..235fe4a 100644 --- a/test/glentities_test.gleam +++ b/test/glentities_test.gleam @@ -1,3 +1,4 @@ +import gleam/string import gleeunit import gleeunit/should import glentities @@ -74,3 +75,32 @@ pub fn roundtrip_hex_test() { input, ) } + +pub fn tco_test() { + let input = + string.repeat( + "I will never try to be clever in tail call recursive languages again", + 100, + ) + + should.equal( + input + |> glentities.encode(glentities.Hex) + |> glentities.decode(), + input, + ) + + should.equal( + input + |> glentities.encode(glentities.Named) + |> glentities.decode(), + input, + ) + + should.equal( + input + |> glentities.encode(glentities.HTMLBody) + |> glentities.decode(), + input, + ) +}