mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Avoid multiple execution of AddToPreamble and friends
When trying to read a textclass, read(Lexer, Readtype) parses and executes the first token and only then verifies that its effect was to set format properly. Otherwise it exits. This is wrong, because if the first tag is "AddToPreamble", then it will have modified the preamble by the time we notice it was not "Format" and therefore exit. The new code starts by requiring a correct "Format" tag. Fixes bug #10725.
This commit is contained in:
parent
bebfa84d79
commit
ebb9d7b058
@ -408,11 +408,14 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
|
||||
if (!lexrc.isOK())
|
||||
return ERROR;
|
||||
|
||||
// Format of files before the 'Format' tag was introduced
|
||||
int format = 1;
|
||||
bool error = false;
|
||||
// The first usable line should be
|
||||
// Format LAYOUT_FORMAT
|
||||
if (lexrc.lex() != TC_FORMAT || !lexrc.next()
|
||||
|| lexrc.getInteger() != LAYOUT_FORMAT)
|
||||
return FORMAT_MISMATCH;
|
||||
|
||||
// parsing
|
||||
bool error = false;
|
||||
while (lexrc.isOK() && !error) {
|
||||
int le = lexrc.lex();
|
||||
|
||||
@ -437,8 +440,8 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
|
||||
switch (static_cast<TextClassTags>(le)) {
|
||||
|
||||
case TC_FORMAT:
|
||||
if (lexrc.next())
|
||||
format = lexrc.getInteger();
|
||||
lexrc.next();
|
||||
lexrc.printError("Duplicate Format directive");
|
||||
break;
|
||||
|
||||
case TC_OUTPUTFORMAT:
|
||||
@ -853,11 +856,6 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
|
||||
error = !readOutlinerName(lexrc);
|
||||
break;
|
||||
} // end of switch
|
||||
|
||||
// Note that this is triggered the first time through the loop unless
|
||||
// we hit a format tag.
|
||||
if (format != LAYOUT_FORMAT)
|
||||
return FORMAT_MISMATCH;
|
||||
}
|
||||
|
||||
// at present, we abort if we encounter an error,
|
||||
|
Loading…
Reference in New Issue
Block a user