]> git.lyx.org Git - features.git/commitdiff
Handle encoding error in layout file parsing more gracefully
authorJuergen Spitzmueller <spitz@lyx.org>
Thu, 13 Feb 2020 07:13:22 +0000 (08:13 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 14 Feb 2020 07:05:17 +0000 (08:05 +0100)
Issue a warning about non-decodable files, but do not break
completely.

Addresses #11736

(cherry picked from commit c4da8d38c9d235c6da85c554c391ad4a5b6d958e)

lib/configure.py
status.23x

index c115ac15aa3d9ab7e91594b7969b2d6ab6f241f9..602e090af5a8af46cc215dd4a1f495cf45d2b44a 100644 (file)
@@ -1417,25 +1417,34 @@ def checkLatexConfig(check_config, bool_docbook):
         classname = file.split(os.sep)[-1].split('.')[0]
         decline = ""
         catline = ""
-        for line in open(file, 'r', encoding='utf8').readlines():
-            if not empty.match(line) and line[0] != '#'[0]:
-                if decline == "":
-                    logger.warning("Failed to find valid \Declare line "
-                        "for layout file `%s'.\n\t=> Skipping this file!" % file)
-                    nodeclaration = True
-                # A class, but no category declaration. Just break.
+        try:
+            for line in open(file, 'r', encoding='utf8').readlines():
+                if not empty.match(line) and line[0] != '#'[0]:
+                    if decline == "":
+                        logger.warning("Failed to find valid \Declare line "
+                            "for layout file `%s'.\n\t=> Skipping this file!" % file)
+                        nodeclaration = True
+                    # A class, but no category declaration. Just break.
+                    break
+                if declare.match(line) != None:
+                    decline = "\\TestDocClass{%s}{%s}" % (classname, line[1:].strip())
+                    testclasses.append(decline)
+                elif category.match(line) != None:
+                    catline = ("\\DeclareCategory{%s}{%s}"
+                               % (classname, category.match(line).groups()[0]))
+                    testclasses.append(catline)
+                if catline == "" or decline == "":
+                    continue
                 break
-            if declare.match(line) != None:
-                decline = "\\TestDocClass{%s}{%s}" % (classname, line[1:].strip())
-                testclasses.append(decline)
-            elif category.match(line) != None:
-                catline = ("\\DeclareCategory{%s}{%s}"
-                           % (classname, category.match(line).groups()[0]))
-                testclasses.append(catline)
-            if catline == "" or decline == "":
+            if nodeclaration:
                 continue
-            break
-        if nodeclaration:
+        except UnicodeDecodeError:
+            logger.warning("**************************************************\n"
+                           "Layout file '%s'\n"
+                           "cannot be decoded in utf-8.\n"
+                           "Please check if the file has the correct encoding.\n"
+                           "Skipping this file!\n"
+                           "**************************************************" % file)
             continue
     testclasses.sort()
     cl = open('chklayouts.tex', 'w', encoding='utf8')
index 147b17bad7f53a9c5fb9c35c2d50672d12412b4a..7b202f9da9a775f2315f50bac5914d0a53acdc5e 100644 (file)
@@ -53,6 +53,7 @@ What's new
 
 - Correctly strike out deleted text after deleted display math (bug 11716).
 
+
 * USER INTERFACE
 
 - Fix backspace deletion of selected items with change tracking (bug 11630).
@@ -84,11 +85,12 @@ What's new
 
 
 
-
 * ADVANCED FIND AND REPLACE
 
 
 
-
 * BUILD/INSTALLATION
 
+- Do not break configuration if a layout file is not decodable. Rather than that, 
+  issue a warning and skip that file (bug 11736).
+