diff options
author | Anthon van der Neut <anthon@mnt.org> | 2016-09-06 15:10:08 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2016-09-06 15:10:08 +0200 |
commit | 805edabe3b233efaa7175c8b7b38cc37968bc0d7 (patch) | |
tree | c708f911f1786aff464a494b01debf6f59ea1aa5 | |
parent | 898025fcaefa8d29763213c9966873334c1f6760 (diff) | |
download | ruamel.yaml-805edabe3b233efaa7175c8b7b38cc37968bc0d7.tar.gz |
fix for issue #58, endless loop in token scanning
-rw-r--r-- | README.rst | 4 | ||||
-rw-r--r-- | __init__.py | 2 | ||||
-rw-r--r-- | _test/test_comments.py | 23 | ||||
-rw-r--r-- | scanner.py | 4 |
4 files changed, 32 insertions, 1 deletions
@@ -18,6 +18,10 @@ ChangeLog :: + 0.12.11 (2016-09-06): + - Fix issue 58 endless loop in scanning tokens (reported by + Christopher Lambert) + 0.12.10 (2016-09-05): - Make previous fix depend on unicode char width (32 bit unicode support is a problem on MacOS reported by David Tagatac) diff --git a/__init__.py b/__init__.py index 69a0d81..eb634fb 100644 --- a/__init__.py +++ b/__init__.py @@ -9,7 +9,7 @@ from __future__ import absolute_import _package_data = dict( full_package_name="ruamel.yaml", - version_info=(0, 12, 10), + version_info=(0, 12, 11, "dev"), author="Anthon van der Neut", author_email="a.van.der.neut@ruamel.eu", description="ruamel.yaml is a YAML parser/emitter that supports roundtrip preservation of comments, seq/map flow style, and map key order", # NOQA diff --git a/_test/test_comments.py b/_test/test_comments.py index 4014509..b858fbc 100644 --- a/_test/test_comments.py +++ b/_test/test_comments.py @@ -592,6 +592,29 @@ class TestEmptyLines: print(line + '$') assert stripped == y + def test_issue_54_not_ok(self): + yaml_str = dedent("""\ + toplevel: + + # some comment + sublevel: 300 + """) + d = round_trip_load(yaml_str) + print(d.ca) + y = round_trip_dump(d, indent=4) + print(y.replace('\n', '$\n')) + assert yaml_str == y + + def test_issue_54_ok(self): + yaml_str = dedent("""\ + toplevel: + # some comment + sublevel: 300 + """) + d = round_trip_load(yaml_str) + y = round_trip_dump(d, indent=4) + assert yaml_str == y + class TestUnicodeComments: @pytest.mark.skipif(ruamel.yaml.reader.Reader.UNICODE_SIZE < 4, @@ -1653,6 +1653,9 @@ class RoundTripScanner(Scanner): while ch: ch = self.scan_line_break(empty_line=True) comment += ch + if self.peek() == '#': # empty line followed by indented real cmment + comment = comment.rsplit('\n', 1)[0] + '\n' + print('comment', repr(comment), self.peek() == '#') end_mark = self.get_mark() return comment, start_mark, end_mark else: @@ -1678,6 +1681,7 @@ class RoundTripScanner(Scanner): self.forward() return ch elif empty_line and ch in '\t ': + self.forward() return ch return u'' |