From 9459ede7f9520011e44371c98a9d6173bfeb7cf6 Mon Sep 17 00:00:00 2001 From: xi Date: Sun, 30 Jul 2006 12:51:05 +0000 Subject: [PATCH] Fix a bug when a block scalar is incorrectly emitted in the simple key context. git-svn-id: http://svn.pyyaml.org/pyyaml/trunk@218 18f92427-320e-0410-9341-c67f048884a3 --- lib/yaml/emitter.py | 5 +++-- tests/data/emit-block-scalar-in-simple-key-context-bug.canonical | 6 ++++++ tests/data/emit-block-scalar-in-simple-key-context-bug.data | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/data/emit-block-scalar-in-simple-key-context-bug.canonical create mode 100644 tests/data/emit-block-scalar-in-simple-key-context-bug.data diff --git a/lib/yaml/emitter.py b/lib/yaml/emitter.py index 95f59db..2ac6c3b 100644 --- a/lib/yaml/emitter.py +++ b/lib/yaml/emitter.py @@ -492,7 +492,8 @@ class Emitter: or (not self.flow_level and self.analysis.allow_block_plain))): return '' if self.event.style and self.event.style in '|>': - if not self.flow_level and self.analysis.allow_block: + if (not self.flow_level and not self.simple_key_context + and self.analysis.allow_block): return self.event.style if not self.event.style or self.event.style == '\'': if (self.analysis.allow_single_quoted and @@ -670,7 +671,7 @@ class Emitter: if index == 0: # Leading indicators are special characters. - if ch in u'#,[]{}#&*!|>\'\"%@`': + if ch in u'#,[]{}&*!|>\'\"%@`': flow_indicators = True block_indicators = True if ch in u'?:': diff --git a/tests/data/emit-block-scalar-in-simple-key-context-bug.canonical b/tests/data/emit-block-scalar-in-simple-key-context-bug.canonical new file mode 100644 index 0000000..473bed5 --- /dev/null +++ b/tests/data/emit-block-scalar-in-simple-key-context-bug.canonical @@ -0,0 +1,6 @@ +%YAML 1.1 +--- !!map +{ + ? !!str "foo" + : !!str "bar" +} diff --git a/tests/data/emit-block-scalar-in-simple-key-context-bug.data b/tests/data/emit-block-scalar-in-simple-key-context-bug.data new file mode 100644 index 0000000..b6b42ba --- /dev/null +++ b/tests/data/emit-block-scalar-in-simple-key-context-bug.data @@ -0,0 +1,4 @@ +? |- + foo +: |- + bar -- 2.11.4.GIT