Skip to content

Commit

Permalink
Fix uiri#68: correctly handle whitespace in multiline strings.
Browse files Browse the repository at this point in the history
Previously, the library would trim all whitespace in multiline strings, even
when the string was a multiline _literal_ string. This resolves that issue,
leaving all whitespace in multiline literal strings.
  • Loading branch information
SergioBenitez committed Dec 3, 2016
1 parent 93236c2 commit 1b8e8f4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ def loads(s, _dict=dict):
if openstring or multilinestr:
if not multilinestr:
raise TomlDecodeError("Unbalanced quotes")
if sl[i-1] == "'" or sl[i-1] == '"':
sl[i] = sl[i-1]
sl[i-3] = ' '
elif openarr:
sl[i] = ' '
else:
Expand All @@ -190,9 +187,12 @@ def loads(s, _dict=dict):
multilinestr = ""
multibackslash = False
for line in s:
line = line.strip()
if line == "":
if not multikey or multibackslash:
line = line.strip()
if line == "" and not multikey:
continue
if multilinestr == "'''\n":
mutlilinestr = "'''"
if multikey:
if multibackslash:
multilinestr += line
Expand Down Expand Up @@ -369,8 +369,10 @@ def _load_line(line, currentlevel, multikey, multibackslash):
k -= 1
if multibackslash:
multilinestr = pair[1][:-1]
else:
elif len(pair[1]) > 3:
multilinestr = pair[1] + "\n"
else:
multilinestr = pair[1]
multikey = pair[0]
else:
value, vtype = _load_value(pair[1], strictly_valid)
Expand Down

0 comments on commit 1b8e8f4

Please sign in to comment.