On Tuesday, 7 March 2017 12.39.19 WET Enrico Forestieri wrote:
> > Is this a valid process that we should support?
>
> Given that lyx2lyx processes text files, taking into account that they
> may have a BOM is safer.
OK. So I will try to solve this problem.
> > If so the following patch fixes this for me, for both python 2 and 3.
>
> I think you can safely commit it.
I send attached another fix that fixes the file as soon as it is read. I am
happier with this version.
Again I tried with python2 and python3 and it works. :-)
Regards,
--
José Abílio
diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py
index 77ccdd0..b924690 100644
--- a/lib/lyx2lyx/LyX.py
+++ b/lib/lyx2lyx/LyX.py
@@ -29,6 +29,7 @@ import sys
import re
import time
import io
+import codecs
try:
import lyx2lyx_version
@@ -304,12 +305,20 @@ class LyX_base:
# use latin1. This works since a) the parts we are interested in are
# pure ASCII (subset of latin1) and b) in contrast to pure ascii or
# utf8, one can decode any 8byte string using latin1.
+ first_line = True
while True:
line = self.input.readline()
if not line:
# eof found before end of header
self.error("Invalid LyX file: Missing body.")
+ if first_line:
+ # Remove UTF8 BOM marker if present
+ if line.startswith(codecs.BOM_UTF8):
+ line = line[len(codecs.BOM_UTF8):]
+
+ first_line = False
+
if PY2:
line = trim_eol(line)
decoded = line