From f751225ea065d36ecaba5d1c28c27d98e57599b7 Mon Sep 17 00:00:00 2001 From: Michael Fellinger Date: Sat, 3 Jan 2026 00:21:46 +0100 Subject: [PATCH] fix another hash-in-string bug --- CHANGELOG.md | 4 ++++ src/tom.gleam | 2 ++ test/tom_test.gleam | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0798736..e4e0e96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v2.0.1 - 2026-01-13 + +- Fixed a bug where the '#' symbol in ''' strings would be treated like a comment + ## v2.0.0 - 2025-05-31 - Added [gleam_time](https://hexdocs.pm/gleam_time/index.html) as a dependency. diff --git a/src/tom.gleam b/src/tom.gleam index ecb73f0..7ce1325 100644 --- a/src/tom.gleam +++ b/src/tom.gleam @@ -709,6 +709,8 @@ fn drop_comments(input: Tokens, acc: Tokens, in_string: Bool) -> Tokens { ["\\", "\"", ..input] if in_string -> drop_comments(input, ["\"", "\\", ..acc], in_string) ["\"", ..input] -> drop_comments(input, ["\"", ..acc], !in_string) + ["'", "'", "'", ..input] -> + drop_comments(input, ["'", "'", "'", ..acc], !in_string) ["#", ..input] if in_string -> drop_comments(input, ["#", ..acc], in_string) ["#", ..input] if !in_string -> input diff --git a/test/tom_test.gleam b/test/tom_test.gleam index 47d6b95..dd1986e 100644 --- a/test/tom_test.gleam +++ b/test/tom_test.gleam @@ -508,6 +508,25 @@ pub fn parse_multi_line_single_quote_string_too_many_quotes_test() { |> should.equal(Error(tom.Unexpected("''''", "'''"))) } +pub fn parse_multi_line_literal_string_with_hash_test() { + let expected = + dict.from_list([ + #( + "a", + tom.String( + "This string contains a #hash character\nand more text after it\n", + ), + ), + ]) + "a = ''' +This string contains a #hash character +and more text after it +''' +" + |> tom.parse + |> should.equal(Ok(expected)) +} + pub fn parse_multi_line_string_escape_newline_test() { let expected = dict.from_list([