File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -39,3 +39,13 @@ def test_parser_should_raise_an_error_if_equal_not_found():
3939 parser = Parser (content )
4040 with pytest .raises (UnexpectedCharError ):
4141 parser .parse ()
42+
43+
44+ def test_parse_multiline_string_ignore_the_first_newline ():
45+ content = 'a = """\n foo\n """'
46+ parser = Parser (content )
47+ assert parser .parse () == {"a" : "foo\n " }
48+
49+ content = 'a = """\r \n foo\n """'
50+ parser = Parser (content )
51+ assert parser .parse () == {"a" : "foo\n " }
Original file line number Diff line number Diff line change @@ -799,9 +799,17 @@ def _parse_string(self, delim: StringType) -> String:
799799 value = ""
800800
801801 # A newline immediately following the opening delimiter will be trimmed.
802- if delim .is_multiline () and self ._current == "\n " :
803- # consume the newline, EOF here is an issue (middle of string)
804- self .inc (exception = UnexpectedEofError )
802+ if delim .is_multiline ():
803+ if self ._current == "\n " :
804+ # consume the newline, EOF here is an issue (middle of string)
805+ self .inc (exception = UnexpectedEofError )
806+ else :
807+ cur = self ._current
808+ with self ._state (restore = True ):
809+ if self .inc ():
810+ cur += self ._current
811+ if cur == "\r \n " :
812+ self .inc_n (2 , exception = UnexpectedEofError )
805813
806814 escaped = False # whether the previous key was ESCAPE
807815 while True :
You can’t perform that action at this time.
0 commit comments