]> git.lyx.org Git - features.git/commitdiff
Prevent the most important case of bug #9012
authorGeorg Baum <baum@lyx.org>
Sun, 9 Mar 2014 09:30:20 +0000 (10:30 +0100)
committerGeorg Baum <baum@lyx.org>
Sun, 9 Mar 2014 09:30:20 +0000 (10:30 +0100)
Currently you can easily create an uncompilable document if you insert
non-ASCII characters in a pass-through paragraph (e.g. ERT inset or verbatim
style). This commit prevents entering these characters directly, but of
course they can still be inserted via tricks, e.g. changing a standard
paragraph to verbatim. A complete fix would handle this case as well,
and also change the fixed latin1 encoding of latex_language to a dynamic one,
so that a verbatim paragraph can contain any character that is encodable in
the encoding of its environment.

src/Text.cpp

index 70805dfe8408b4c465bb1ffe054805eac85a022d..c4cac8892ecd726c09a02d1a26e8db10c2d4615d 100644 (file)
@@ -30,6 +30,7 @@
 #include "Cursor.h"
 #include "CutAndPaste.h"
 #include "DispatchResult.h"
+#include "Encoding.h"
 #include "ErrorList.h"
 #include "FuncRequest.h"
 #include "factory.h"
@@ -1004,6 +1005,16 @@ void Text::insertChar(Cursor & cur, char_type c)
                }
        }
 
+       // Prevent to insert uncodable characters in verbatim and ERT
+       // (workaround for bug 9012)
+       if (cur.paragraph().isPassThru() && cur.current_font.language()) {
+               Encoding const * e = cur.current_font.language()->encoding();
+               if (!e->encodable(c)) {
+                       cur.message(_("Character is uncodable in verbatim paragraphs."));
+                       return;
+               }
+       }
+
        par.insertChar(cur.pos(), c, cur.current_font,
                cur.buffer()->params().trackChanges);
        cur.checkBufferStructure();