From 5586d4577054cd33ccbccc235c2fb950098e96c5 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 26 Apr 2026 17:32:43 +0100 Subject: [PATCH] fix: fix a parser hang --- tests/test_parser.py | 12 ++++++++++++ tomlkit/parser.py | 2 ++ 2 files changed, 14 insertions(+) diff --git a/tests/test_parser.py b/tests/test_parser.py index eeb376e..5e7d9f1 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -51,3 +51,15 @@ def test_parse_multiline_string_ignore_the_first_newline() -> None: content = 'a = """\r\nfoo\n"""' parser = Parser(content) assert parser.parse() == {"a": "foo\n"} + + +def test_parse_multiline_basic_string_with_crlf() -> None: + content = 'a = """foo\r\nbar"""' + parser = Parser(content) + assert parser.parse() == {"a": "foo\r\nbar"} + + +def test_parse_multiline_literal_string_with_crlf() -> None: + content = "a = '''foo\r\nbar'''" + parser = Parser(content) + assert parser.parse() == {"a": "foo\r\nbar"} diff --git a/tomlkit/parser.py b/tomlkit/parser.py index 538ed03..00079e6 100644 --- a/tomlkit/parser.py +++ b/tomlkit/parser.py @@ -860,6 +860,8 @@ def _parse_string(self, delim: StringType) -> String: with self._state(restore=True): if not self.inc() or self._current != "\n": raise self.parse_error(InvalidControlChar, CTRL_M, "strings") + value += self._current + self.inc(exception=UnexpectedEofError) elif not escaped and self._current == delim.unit: # try to process current as a closing delim original = self.extract()