Commits

Kirill Simonov committed ff0d4fb

Fix a bug when a block scalar is incorrectly emitted in the simple key context.

  • Participants
  • Parent commits 9972e25

Comments (0)

Files changed (3)

lib/yaml/emitter.py

                     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
 
             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'?:':

tests/data/emit-block-scalar-in-simple-key-context-bug.canonical

+%YAML 1.1
+--- !!map
+{
+  ? !!str "foo"
+  : !!str "bar"
+}

tests/data/emit-block-scalar-in-simple-key-context-bug.data

+? |-
+  foo
+: |-
+  bar