Skip to content

Commit 96a4d22

Browse files
authored
fix: fix a parser hang (#470)
1 parent 843f799 commit 96a4d22

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

tests/test_parser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,15 @@ def test_parse_multiline_string_ignore_the_first_newline() -> None:
5151
content = 'a = """\r\nfoo\n"""'
5252
parser = Parser(content)
5353
assert parser.parse() == {"a": "foo\n"}
54+
55+
56+
def test_parse_multiline_basic_string_with_crlf() -> None:
57+
content = 'a = """foo\r\nbar"""'
58+
parser = Parser(content)
59+
assert parser.parse() == {"a": "foo\r\nbar"}
60+
61+
62+
def test_parse_multiline_literal_string_with_crlf() -> None:
63+
content = "a = '''foo\r\nbar'''"
64+
parser = Parser(content)
65+
assert parser.parse() == {"a": "foo\r\nbar"}

tomlkit/parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,8 @@ def _parse_string(self, delim: StringType) -> String:
860860
with self._state(restore=True):
861861
if not self.inc() or self._current != "\n":
862862
raise self.parse_error(InvalidControlChar, CTRL_M, "strings")
863+
value += self._current
864+
self.inc(exception=UnexpectedEofError)
863865
elif not escaped and self._current == delim.unit:
864866
# try to process current as a closing delim
865867
original = self.extract()

0 commit comments

Comments
 (0)