commit 435c1bbac7b1492fdfd8d5bd21c9c9363387f216
Author: Enrico Forestieri <for...@lyx.org>
Date:   Sat Aug 15 18:32:41 2015 +0200

    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.

diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 7a641e0..dddbf78 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -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

Reply via email to