]> git.lyx.org Git - features.git/commitdiff
Fix bug #9622
authorEnrico Forestieri <forenr@lyx.org>
Fri, 14 Dec 2018 10:41:16 +0000 (11:41 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 12:39:51 +0000 (14:39 +0200)
The backslash is the escape character used in our parser. Hence,
when used as a path separator on Windows, it has to be itself
escaped or the path enclosed in either double or single quotes.
Windows users are maybe trained to quote paths containing spaces
but not paths with backslashes. So, we automatically escape the
backslashes when they are not already enclosed in quotes.

src/Format.cpp

index ab09d4a6ded716807baa3dffcb322fa56db5dc8a..a6727a2d8128a8c67e670912ad559b0d66b901f8 100644 (file)
@@ -682,6 +682,28 @@ bool Formats::view(Buffer const & buffer, FileName const & filename,
 
        string command = format->viewer();
 
+       // Escape backslashes if not already in double or single quotes.
+       // We cannot simply quote the whole command as there may be arguments.
+       if (contains(command, '\\')) {
+               bool inquote1 = false;
+               bool inquote2 = false;
+               string::iterator cit = command.begin();
+               for (; cit != command.end(); ++cit) {
+                       switch (*cit) {
+                       case '"':
+                               inquote1 = !inquote1;
+                               break;
+                       case '\'':
+                               inquote2 = !inquote2;
+                               break;
+                       case '\\':
+                               if (!inquote1 && !inquote2)
+                                       cit = ++command.insert(cit, '\\');
+                               break;
+                       }
+               }
+       }
+
        if (format_name == "dvi" &&
            !lyxrc.view_dvi_paper_option.empty()) {
                string paper_size = buffer.params().paperSizeName(BufferParams::XDVI);