commit 72c6602b13b0fb09f80fa742266c78a50e8bb73c
Author: Georg Baum <b...@lyx.org>
Date:   Sat Jun 11 14:45:18 2016 +0200

    Improve comments and add missing decoding call
    
    We do already fill the first line of the body in the first pass, so the body
    has to be converted to the correct encoding as well.

diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index fa2bbba..d98d765 100644
--- a/lib/lyx2lyx/LyX.py
+++ b/lib/lyx2lyx/LyX.py
@@ -280,17 +280,20 @@ class LyX_base:
         """Reads a file into the self.header and
         self.body parts, from self.input."""
 
+        # First pass: Read header to determine file encoding
         while True:
             line = self.input.readline()
             if not line:
-                self.error("Invalid LyX file.")
+                # eof found before end of header
+                self.error("Invalid LyX file: Missing body.")
 
             line = trim_eol(line)
             if check_token(line, '\\begin_preamble'):
                 while 1:
                     line = self.input.readline()
                     if not line:
-                        self.error("Invalid LyX file.")
+                        # eof found before end of header
+                        self.error("Invalid LyX file: Missing body.")
 
                     line = trim_eol(line)
                     if check_token(line, '\\end_preamble'):
@@ -345,6 +348,8 @@ class LyX_base:
             self.header[i] = self.header[i].decode(self.encoding)
         for i in range(len(self.preamble)):
             self.preamble[i] = self.preamble[i].decode(self.encoding)
+        for i in range(len(self.body)):
+            self.body[i] = self.body[i].decode(self.encoding)
 
         # Read document body
         while 1:

Reply via email to