]> git.lyx.org Git - features.git/commitdiff
Do not allow pasting backslashes in macro names
authorEnrico Forestieri <forenr@lyx.org>
Sun, 20 Nov 2022 18:01:38 +0000 (19:01 +0100)
committerEnrico Forestieri <forenr@lyx.org>
Sun, 20 Nov 2022 18:01:38 +0000 (19:01 +0100)
Backslashes are not allowed in macro names and LyX
enforces this by not allowing entering them by keyboard.
However, it was possible to paste them and this may cause
crashes (see bug #12596).

src/mathed/InsetMathNest.cpp

index 54d96d919097ca286f47373b77d4f632cee484cc..70ef1858c4cdec570446fc0ba842055e0a6e231f 100644 (file)
@@ -548,6 +548,15 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
                        topaste = cap::selection(n, make_pair(buffer().params().documentClassPtr(),
                                                              buffer().params().authors()));
                }
+               InsetMath const * im = cur.inset().asInsetMath();
+               InsetMathMacro const * macro = im ? im->asMacro() : nullptr;
+               // do not allow pasting a backslash in the name of a macro
+               if (macro
+                   && macro->displayMode() == InsetMathMacro::DISPLAY_UNFOLDED
+                   && support::contains(topaste, char_type('\\'))) {
+                       LYXERR0("Removing backslash from pasted string");
+                       topaste = subst(topaste, from_ascii("\\"), docstring());
+               }
                cur.niceInsert(topaste, parseflg, false);
                cur.clearSelection(); // bug 393
                cur.forceBufferUpdate();