[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lyx-cvs
Subject:    [LyX/master] Do not corrupt documents without newline at EOF
From:       Georg Baum <baum () lyx ! org>
Date:       2014-05-29 11:18:53
Message-ID: 20140529111853.F0BDE2802B6 () lyx ! lyx ! org
[Download RAW message or body]

commit c75c6e446a8bc0dbaabaf156c0abfd622c050129
Author: Georg Baum <baum@lyx.org>
Date:   Thu May 29 13:15:07 2014 +0200

    Do not corrupt documents without newline at EOF
    
    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.

diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index e37691f..93006c3 100644
--- a/lib/lyx2lyx/LyX.py
+++ b/lib/lyx2lyx/LyX.py
@@ -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:

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic