]> git.lyx.org Git - features.git/commitdiff
Do not corrupt documents without newline at EOF
authorGeorg Baum <baum@lyx.org>
Thu, 29 May 2014 11:15:07 +0000 (13:15 +0200)
committerGeorg Baum <baum@lyx.org>
Thu, 29 May 2014 11:15:07 +0000 (13:15 +0200)
trim_eol() assumes that a line always ends either with \n, \r, or \r\n.
This assumption is always valid except for the last line of a document, since it
may miss the trailing newline. LyX does not create such documents, bu they may
result from automatic creation tools, and LyX can read them, so lyx2lyx should
be able to read them as well.

lib/lyx2lyx/LyX.py

index e37691f273d11969af9bcea2828ad031f5396f7f..93006c34e1121dc1e9bcb77803ece69eebaa85fb 100644 (file)
@@ -147,6 +147,9 @@ def get_backend(textclass):
 
 def trim_eol(line):
     " Remove end of line char(s)."
+    if line[-1] != '\n':
+        # May happen for the last line of a document
+        return line
     if line[-2:-1] == '\r':
         return line[:-2]
     else: