From 10438bc786dc6a381193025779cf86e072a1108a Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Mon, 26 Nov 2018 09:24:31 +0100 Subject: fix for issue with folds after (and before) spaces being emitted as BEL character instead of discarding --- CHANGES | 4 ++++ README.rst | 10 +++++++--- __init__.py | 4 ++-- _doc/_static/pypi.svg | 2 +- emitter.py | 13 ++++++++----- nodes.py | 7 ++++--- representer.py | 6 +++++- scalarstring.py | 2 +- 8 files changed, 32 insertions(+), 16 deletions(-) diff --git a/CHANGES b/CHANGES index dad1a5c..9d17020 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +[0, 15, 80]: 2018-11-26 + - fix issue emitting BEL character when round-tripping invalid folded input + (reported by Isaac on `StackOverflow `__) + [0, 15, 79]: 2018-11-21 - fix issue with anchors nested deeper than alias (reported by gaFF on `StackOverflow `__) diff --git a/README.rst b/README.rst index 69eed0c..61f7b52 100644 --- a/README.rst +++ b/README.rst @@ -4,8 +4,8 @@ ruamel.yaml ``ruamel.yaml`` is a YAML 1.2 loader/dumper package for Python. -:version: 0.15.79 -:updated: 2018-11-21 +:version: 0.15.80 +:updated: 2018-11-26 :documentation: http://yaml.readthedocs.io :repository: https://bitbucket.org/ruamel/ :pypi: https://pypi.org/project/ruamel.yaml/ @@ -54,6 +54,10 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) +0.15.80 (2018-11-26): + - fix issue emitting BEL character when round-tripping invalid folded input + (reported by Isaac on `StackOverflow `__) + 0.15.79 (2018-11-21): - fix issue with anchors nested deeper than alias (reported by gaFF on `StackOverflow `__) @@ -145,7 +149,7 @@ ChangeLog 0.15.64 (2018-08-30): - support round-trip of tagged sequences: ``!Arg [a, {b: 1}]`` - - single entry mappings in flow sequences now written by default without quotes + - single entry mappings in flow sequences now written by default without braces, set ``yaml.brace_single_entry_mapping_in_flow_sequence=True`` to force getting ``[a, {b: 1}, {c: {d: 2}}]`` instead of the default ``[a, b: 1, c: {d: 2}]`` - fix issue when roundtripping floats starting with a dot such as ``.5`` diff --git a/__init__.py b/__init__.py index 9988df7..8033a8b 100644 --- a/__init__.py +++ b/__init__.py @@ -7,8 +7,8 @@ if False: # MYPY _package_data = dict( full_package_name='ruamel.yaml', - version_info=(0, 15, 79), - __version__='0.15.79', + version_info=(0, 15, 80), + __version__='0.15.80', 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/_doc/_static/pypi.svg b/_doc/_static/pypi.svg index e9d13c5..7c76e41 100644 --- a/_doc/_static/pypi.svg +++ b/_doc/_static/pypi.svg @@ -1 +1 @@ - pypipypi0.15.790.15.79 + pypipypi0.15.800.15.80 diff --git a/emitter.py b/emitter.py index c410f2e..61ca269 100644 --- a/emitter.py +++ b/emitter.py @@ -156,8 +156,8 @@ class Emitter(object): self.column = 0 self.whitespace = True self.indention = True - self.compact_seq_seq = True # dash after dash - self.compact_seq_map = True # key after dash + self.compact_seq_seq = True # dash after dash + self.compact_seq_map = True # key after dash # self.compact_ms = False # dash after key, only when excplicit key with ? self.no_newline = None # type: Optional[bool] # set if directly after `- ` @@ -1463,9 +1463,12 @@ class Emitter(object): data = data.encode(self.encoding) self.stream.write(data) if ch == u'\a': - self.write_line_break() - self.write_indent() - end += 2 # \a and the space that is inserted on the fold + if end < (len(text) - 1) and not text[end + 2].isspace(): + self.write_line_break() + self.write_indent() + end += 2 # \a and the space that is inserted on the fold + else: + raise EmitterError('unexcpected fold indicator \\a before space') if ch is None: self.write_line_break() start = end diff --git a/nodes.py b/nodes.py index d99e909..da86e9c 100644 --- a/nodes.py +++ b/nodes.py @@ -78,15 +78,16 @@ class ScalarNode(Node): __slots__ = ('style',) id = 'scalar' - def __init__(self, tag, value, start_mark=None, end_mark=None, style=None, comment=None, - anchor=None): + def __init__( + self, tag, value, start_mark=None, end_mark=None, style=None, comment=None, anchor=None + ): # type: (Any, Any, Any, Any, Any, Any, Any) -> None Node.__init__(self, tag, value, start_mark, end_mark, comment=comment, anchor=anchor) self.style = style class CollectionNode(Node): - __slots__ = ('flow_style', ) + __slots__ = ('flow_style',) def __init__( self, diff --git a/representer.py b/representer.py index 143b7d5..7ce810e 100644 --- a/representer.py +++ b/representer.py @@ -691,7 +691,11 @@ class RoundTripRepresenter(SafeRepresenter): tag = None style = '>' for fold_pos in reversed(getattr(data, 'fold_pos', [])): - if data[fold_pos] == ' ': + if ( + data[fold_pos] == ' ' + and (fold_pos > 0 and not data[fold_pos - 1].isspace()) + and (fold_pos < len(data) and not data[fold_pos + 1].isspace()) + ): data = data[:fold_pos] + '\a' + data[fold_pos:] if PY2 and not isinstance(data, unicode): data = unicode(data, 'ascii') diff --git a/scalarstring.py b/scalarstring.py index c7b1a78..0566164 100644 --- a/scalarstring.py +++ b/scalarstring.py @@ -21,7 +21,7 @@ __all__ = [ class ScalarString(text_type): - __slots__ = (Anchor.attrib) + __slots__ = Anchor.attrib def __new__(cls, *args, **kw): # type: (Any, Any) -> Any -- cgit v1.2.1