From 183e8d1d4abf5fe11e872fd8f5535002ce6ae37f Mon Sep 17 00:00:00 2001 From: xi Date: Tue, 12 Sep 2006 13:53:30 +0000 Subject: [PATCH] Fix loading an empty YAML stream. git-svn-id: http://svn.pyyaml.org/pyyaml/trunk@233 18f92427-320e-0410-9341-c67f048884a3 --- ext/_yaml.pyx | 6 +++--- lib/yaml/composer.py | 9 ++++----- tests/data/empty-document-bug.canonical | 1 + tests/data/empty-document-bug.data | 0 4 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 tests/data/empty-document-bug.canonical create mode 100644 tests/data/empty-document-bug.data diff --git a/ext/_yaml.pyx b/ext/_yaml.pyx index bda7b3f..00d8334 100644 --- a/ext/_yaml.pyx +++ b/ext/_yaml.pyx @@ -651,6 +651,9 @@ cdef class CParser: 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 @@ -661,9 +664,6 @@ cdef class CParser: 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() diff --git a/lib/yaml/composer.py b/lib/yaml/composer.py index 5b48fe0..9f5cd87 100644 --- a/lib/yaml/composer.py +++ b/lib/yaml/composer.py @@ -14,6 +14,10 @@ class Composer(object): 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) @@ -23,11 +27,6 @@ class Composer(object): 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() diff --git a/tests/data/empty-document-bug.canonical b/tests/data/empty-document-bug.canonical new file mode 100644 index 0000000..28a6cf1 --- /dev/null +++ b/tests/data/empty-document-bug.canonical @@ -0,0 +1 @@ +# This YAML stream contains no YAML documents. diff --git a/tests/data/empty-document-bug.data b/tests/data/empty-document-bug.data new file mode 100644 index 0000000..e69de29 -- 2.11.4.GIT