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
{
// 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/");
else if (!lyxrc.save_origin)
filepath = "unavailable";
os << "\\origin " << filepath << '\n';
os << "\\origin " << quoteIfNeeded(filepath) << '\n';
// the textclass
os << "\\textclass " << buf->includedFilePath(addName(buf->layoutPos(),
baseClass()->name()), "layout")
os << "\\textclass "
<< quoteIfNeeded(buf->includedFilePath(addName(buf->layoutPos(),
baseClass()->name()), "layout"))
<< '\n';
// then the preamble