Re: [LyX/master] lyx2lyx: Fix trim_eol_binary() to strip \r on CRLF files
José Matos <[email protected]>
| Newsgroups | gmane.editors.lyx.devel |
|---|---|
| Message-ID | <[email protected]> |
On Tue, 2026-08-04 at 16:43 +0000, Udi Fogiel wrote: > commit e4245896595c733e5e85984b41ea21e158c5a52c > Author: Udi Fogiel <[email protected]> > Date: Tue Aug 4 19:23:54 2026 +0300 > > lyx2lyx: Fix trim_eol_binary() to strip \r on CRLF files > > line[-2:-1] == 13 compares a bytes slice to an int, > which is always False in Python 3 > --- > lib/lyx2lyx/LyX.py | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py > index ab3e915859..ce27d27f95 100644 > --- a/lib/lyx2lyx/LyX.py > +++ b/lib/lyx2lyx/LyX.py > @@ -191,7 +191,7 @@ def trim_eol_binary(line): > if line[-1] != 10 and line[-1] != 13: > # May happen for the last line of a document > return line > - if line[-2:-1] == 13: > + if len(line) >= 2 and line[-2] == 13: > return line[:-2] > else: > return line[:-1] I know that this is not your fault. It is mine. :-) I suggest to make this code explicit, make the condition: ``` if len(line) >= 2 and line[-2] == r'\r': ``` so the idea is really to replace 13 by r'\r'. What do you think? BTW to keep the same analogy as before it could be: ``` if line[-2:-1] == [r'\r']: ``` This is correct in any case. :-) -- José Abílio -- lyx-devel mailing list [email protected] https://lists.lyx.org/mailman/listinfo/lyx-devel