From 0ab85759cf4ceef0672247295f4084fbb8cdb51d Mon Sep 17 00:00:00 2001 From: xi Date: Fri, 30 Jun 2006 08:10:36 +0000 Subject: [PATCH] Fix invalid output of single-quoted scalars in cases when a single quote is not escaped when preceeded by whitespaces or line breaks. (Fix #17). git-svn-id: http://svn.pyyaml.org/pyyaml/trunk@197 18f92427-320e-0410-9341-c67f048884a3 --- lib/yaml/emitter.py | 14 +++++++------- tests/data/invalid-single-quote-bug.code | 1 + tests/data/invalid-single-quote-bug.data | 2 ++ 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 tests/data/invalid-single-quote-bug.code create mode 100644 tests/data/invalid-single-quote-bug.data diff --git a/lib/yaml/emitter.py b/lib/yaml/emitter.py index a34c452..95f59db 100644 --- a/lib/yaml/emitter.py +++ b/lib/yaml/emitter.py @@ -922,13 +922,13 @@ class Emitter: data = data.encode(self.encoding) self.stream.write(data) start = end - if ch == u'\'': - data = u'\'\'' - self.column += 2 - if self.encoding: - data = data.encode(self.encoding) - self.stream.write(data) - start = end + 1 + if ch == u'\'': + data = u'\'\'' + self.column += 2 + if self.encoding: + data = data.encode(self.encoding) + self.stream.write(data) + start = end + 1 if ch is not None: spaces = (ch == u' ') breaks = (ch in u'\n\x85\u2028\u2029') diff --git a/tests/data/invalid-single-quote-bug.code b/tests/data/invalid-single-quote-bug.code new file mode 100644 index 0000000..5558945 --- /dev/null +++ b/tests/data/invalid-single-quote-bug.code @@ -0,0 +1 @@ +["foo 'bar'", "foo\n'bar'"] diff --git a/tests/data/invalid-single-quote-bug.data b/tests/data/invalid-single-quote-bug.data new file mode 100644 index 0000000..76ef7ae --- /dev/null +++ b/tests/data/invalid-single-quote-bug.data @@ -0,0 +1,2 @@ +- "foo 'bar'" +- "foo\n'bar'" -- 2.11.4.GIT