diff --git a/src/emitter.c b/src/emitter.c
index 6c0f5c49ef59f3b436e7890fbf61ca3f7db3b677_c3JjL2VtaXR0ZXIuYw==..64758cef676f33b7dc3fae5f4830f63789b488a0_c3JjL2VtaXR0ZXIuYw== 100644
--- a/src/emitter.c
+++ b/src/emitter.c
@@ -495,6 +495,7 @@
 yaml_emitter_emit_stream_start(yaml_emitter_t *emitter,
         yaml_event_t *event)
 {
+    emitter->open_ended = 0;
     if (event->type == YAML_STREAM_START_EVENT)
     {
         if (!emitter->encoding) {
@@ -594,7 +595,6 @@
         {
             if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
                 return 0;
-            emitter->open_ended = 0;
             if (!yaml_emitter_write_indent(emitter))
                 return 0;
         }
@@ -598,6 +598,7 @@
             if (!yaml_emitter_write_indent(emitter))
                 return 0;
         }
+        emitter->open_ended = 0;
 
         if (event->data.document_start.version_directive) {
             implicit = 0;
@@ -662,7 +663,7 @@
          * This can happen if a block scalar with trailing empty lines
          * is at the end of the stream
          */
-        if (emitter->open_ended)
+        if (emitter->open_ended == 2)
         {
             if (!yaml_emitter_write_indicator(emitter, "...", 1, 0, 0))
                 return 0;
@@ -715,6 +716,8 @@
             if (!yaml_emitter_write_indent(emitter))
                 return 0;
         }
+        else if (!emitter->open_ended)
+            emitter->open_ended = 1;
         if (!yaml_emitter_flush(emitter))
             return 0;
 
@@ -2222,7 +2225,7 @@
         else if (string.start == string.pointer)
         {
             chomp_hint = "+";
-            emitter->open_ended = 1;
+            emitter->open_ended = 2;
         }
         else
         {
@@ -2232,7 +2235,7 @@
             if (IS_BREAK(string))
             {
                 chomp_hint = "+";
-                emitter->open_ended = 1;
+                emitter->open_ended = 2;
             }
         }
     }