Quote argument of tag when necessary

Both \origin and \textclass tags may be paths and contain spaces.
In this case, enclose them in double quotes such that they can be
correctly read by the lexer.
This commit is contained in:
Enrico Forestieri 2015-08-15 18:32:41 +02:00
parent 00e1936d81
commit 435c1bbac7

View File

@ -983,6 +983,16 @@ string BufferParams::readToken(Lexer & lex, string const & token,
} }
namespace {
// Quote argument if it contains spaces
string quoteIfNeeded(string const & str) {
if (contains(str, ' '))
return "\"" + str + "\"";
return str;
}
}
void BufferParams::writeFile(ostream & os, Buffer const * buf) const void BufferParams::writeFile(ostream & os, Buffer const * buf) const
{ {
// The top of the file is written by the buffer. // The top of the file is written by the buffer.
@ -995,11 +1005,12 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
filepath.replace(0, sysdir.length(), "/systemlyxdir/"); filepath.replace(0, sysdir.length(), "/systemlyxdir/");
else if (!lyxrc.save_origin) else if (!lyxrc.save_origin)
filepath = "unavailable"; filepath = "unavailable";
os << "\\origin " << filepath << '\n'; os << "\\origin " << quoteIfNeeded(filepath) << '\n';
// the textclass // the textclass
os << "\\textclass " << buf->includedFilePath(addName(buf->layoutPos(), os << "\\textclass "
baseClass()->name()), "layout") << quoteIfNeeded(buf->includedFilePath(addName(buf->layoutPos(),
baseClass()->name()), "layout"))
<< '\n'; << '\n';
// then the preamble // then the preamble