]> git.lyx.org Git - features.git/commitdiff
Fix problem with validation when using InsetLayout.
authorRichard Kimberly Heck <rikiheck@lyx.org>
Thu, 27 Feb 2020 03:18:58 +0000 (22:18 -0500)
committerRichard Kimberly Heck <rikiheck@lyx.org>
Thu, 27 Feb 2020 03:30:34 +0000 (22:30 -0500)
(cherry picked from commit 2e444dd6570804d33c1fd44713dc3b3f15ec9c5c)

src/TextClass.cpp
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h
status.23x

index 25965c6762ef367d3324964e449dac2aff422b00..56a59520aec595e4d6012c6b7b4e31d577c6c1d7 100644 (file)
@@ -731,6 +731,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                                break;
                        }
                        docstring const name = subst(lexrc.getDocString(), '_', ' ');
+                       bool const validating = (rt == VALIDATION);
                        if (name.empty()) {
                                string s = "Could not read name for InsetLayout: `$$Token' "
                                        + lexrc.getString() + " is probably not valid UTF-8!";
@@ -739,15 +740,17 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
                                // Since we couldn't read the name, we just scan the rest
                                // of the style and discard it.
                                il.read(lexrc, *this);
-                               // Let's try to continue rather than abort.
-                               // error = true;
+                               // Let's try to continue rather than abort, unless we're validating
+                               // in which case we want to report the error
+                               if (validating)
+                                       error = true;
                        } else if (hasInsetLayout(name)) {
                                InsetLayout & il = insetlayoutlist_[name];
-                               error = !il.read(lexrc, *this);
+                               error = !il.read(lexrc, *this, validating);
                        } else {
                                InsetLayout il;
                                il.setName(name);
-                               error = !il.read(lexrc, *this);
+                               error = !il.read(lexrc, *this, validating);
                                if (!error)
                                        insetlayoutlist_[name] = il;
                        }
index 621e784174c5f605953201a2ea100039fa9b8fce..1b8d329914e1bcdbdffaa479856bf9902da51242 100644 (file)
@@ -77,7 +77,8 @@ InsetLayout::InsetLaTeXType translateLaTeXType(std::string const & str)
 } // namespace
 
 
-bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
+bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
+       bool validating)
 {
        enum {
                IL_ADDTOTOC,
@@ -203,6 +204,8 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                switch (le) {
                case Lexer::LEX_UNDEF:
                        lex.printError("Unknown InsetLayout tag");
+                       if (validating)
+                               return false;
                        continue;
                default:
                        break;
@@ -219,13 +222,20 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                                LYXERR0("Flex insets must have names of the form `Flex:<name>'.\n"
                                        "This one has the name `" << to_utf8(name_) << "'\n"
                                        "Ignoring LyXType declaration.");
+                               // this is not really a reason to abort
+                               if (validating)
+                                       return false;
                                break;
                        }
                        string lt;
                        lex >> lt;
                        lyxtype_ = translateLyXType(lt);
-                       if (lyxtype_  == NOLYXTYPE)
+                       if (lyxtype_  == NOLYXTYPE) {
                                LYXERR0("Unknown LyXType `" << lt << "'.");
+                               // this is not really a reason to abort
+                               if (validating)
+                                       return false;
+                       }
                        if (lyxtype_ == CHARSTYLE) {
                                // by default, charstyles force the plain layout
                                multipar_ = false;
@@ -237,8 +247,12 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                        string lt;
                        lex >> lt;
                        latextype_ = translateLaTeXType(lt);
-                       if (latextype_  == ILT_ERROR)
+                       if (latextype_  == ILT_ERROR) {
                                LYXERR0("Unknown LaTeXType `" << lt << "'.");
+                               // this is not really a reason to abort
+                               if (validating)
+                                       return false;
+                       }
                        break;
                }
                case IL_LABELSTRING:
@@ -350,6 +364,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                                                tclass.insetLayouts().end();
                                for (; lit != len; ++lit)
                                        lyxerr << lit->second.name() << "\n";
+                               // this is not really a reason to abort
+                               if (validating)
+                                       return false;
                        }
                        break;
                }
@@ -380,6 +397,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
                                                tclass.insetLayouts().end();
                                for (; lit != len; ++lit)
                                        lyxerr << lit->second.name() << "\n";
+                               // this is not really a reason to abort
+                               if (validating)
+                                       return false;
                        }
                        break;
                }
index c4a12a4018a9e17eaee309c0b4676ba08ed7afe1..d21706818bc832b79708d279565f36baeedbd12f 100644 (file)
@@ -56,7 +56,8 @@ public:
                ILT_ERROR
        };
        ///
-       bool read(Lexer & lexrc, TextClass const & tclass);
+       bool read(Lexer & lexrc, TextClass const & tclass,
+                       bool validating = false);
        ///
        docstring name() const { return name_; }
        ///
index 7b202f9da9a775f2315f50bac5914d0a53acdc5e..8b96ff406a3da18938d81de20361d04be741c870 100644 (file)
@@ -68,6 +68,7 @@ What's new
 - Fix a crash reported on lyx users.
   There was an uninitialized buffer member of MathData in LFUN dispatch.
 
+- Fix problem with validation of InsetLayout.
 
 * INTERNALS