Skip to content

Commit 88ec1ab

Browse files
fix #7; handle multiline keys
1 parent 8e50d5a commit 88ec1ab

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

tests/test_vdf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ def test_parse_exceptions(self):
305305
# invalid syntax
306306
'"asd" "123"\n"zxc" "333"\n"',
307307
'asd 123\nzxc 333\n"',
308+
'"asd\n\n\n\n\nzxc',
308309

309310
# one too many closing parenthasis
310311
'"asd"\n{\n"zxc" "123"\n}\n}\n}\n}\n',

vdf/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ def parse(fp, mapper=dict):
8383
match = re_keyvalue.match(line)
8484

8585
if not match:
86-
raise SyntaxError("vdf.parse: invalid syntax (line %d)" % (idx + 1))
86+
try:
87+
line += next(fp)
88+
except StopIteration:
89+
raise SyntaxError("vdf.parse: unexpected EOF (open key quote?)")
90+
continue
8791

8892
key = match.group('key') if match.group('qkey') is None else match.group('qkey')
8993
val = match.group('val') if match.group('qval') is None else match.group('qval')
@@ -100,7 +104,10 @@ def parse(fp, mapper=dict):
100104
# if the value is line consume one more line and try to match again,
101105
# until we get the KeyValue pair
102106
if match.group('vq_end') is None and match.group('qval') is not None:
103-
line += next(fp)
107+
try:
108+
line += next(fp)
109+
except StopIteration:
110+
raise SyntaxError("vdf.parse: unexpected EOF (open value quote?)")
104111
continue
105112

106113
stack[-1][key] = val

0 commit comments

Comments
 (0)