Commits

Kirill Simonov  committed 4798f75

Fix loading an empty YAML stream.

  • Participants
  • Parent commits f0f0721

Comments (0)

Files changed (4)

File ext/_yaml.pyx

 
     def check_node(self):
         self._parse_next_event()
+        if self.parsed_event.type == YAML_STREAM_START_EVENT:
+            yaml_event_delete(&self.parsed_event)
+            self._parse_next_event()
         if self.parsed_event.type != YAML_STREAM_END_EVENT:
             return True
         return False
             return self._compose_document()
 
     cdef object _compose_document(self):
-        if self.parsed_event.type == YAML_STREAM_START_EVENT:
-            yaml_event_delete(&self.parsed_event)
-            self._parse_next_event()
         yaml_event_delete(&self.parsed_event)
         node = self._compose_node(None, None)
         self._parse_next_event()

File lib/yaml/composer.py

         self.anchors = {}
 
     def check_node(self):
+        # Drop the STREAM-START event.
+        if self.check_event(StreamStartEvent):
+            self.get_event()
+
         # If there are more documents available?
         return not self.check_event(StreamEndEvent)
 
             return self.compose_document()
 
     def compose_document(self):
-
-        # Drop the STREAM-START event.
-        if self.check_event(StreamStartEvent):
-            self.get_event()
-
         # Drop the DOCUMENT-START event.
         self.get_event()
 

File tests/data/empty-document-bug.canonical

+# This YAML stream contains no YAML documents.

File tests/data/empty-document-bug.data

Empty file added.