From 6a36758cae62bdd1a5b0c8229dad6971d22041c3 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 8 Mar 2010 07:05:20 +0000
Subject: [PATCH] allow double quote escaping in -watch string to prevent shell
 expansion

---
 Common/CommandLine.cpp  | 9 +++++++--
 Common/DefaultOptions.h | 2 +-
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp
index aa5c05b6da..ab46b1e3e9 100644
--- a/Common/CommandLine.cpp
+++ b/Common/CommandLine.cpp
@@ -233,8 +233,13 @@ void GetOptions(int argc, char *argv[])
       }
       else if(!strcmp(argv[i] + 1, "watch")) {
         i++;
-        if(argv[i])
-          CTX::instance()->watchFilePattern = argv[i++];
+        if(argv[i]){
+          std::string tmp = argv[i++];
+          if(tmp.size() > 2 && tmp[0] == '"' && tmp[tmp.size() - 1] == '"')
+            CTX::instance()->watchFilePattern = tmp.substr(1, tmp.size() - 2);
+          else
+            CTX::instance()->watchFilePattern = tmp;
+        }
         else
           Msg::Fatal("Missing string");
       }
diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h
index 522136ea01..9184fa1542 100644
--- a/Common/DefaultOptions.h
+++ b/Common/DefaultOptions.h
@@ -97,7 +97,7 @@ StringXString GeneralOptions_String[] = {
 #endif
     "System command to launch a web browser" },
 
-  { F|S, "WatchFilePattern", opt_general_watch_file_pattern , "" ,
+  { F|0, "WatchFilePattern", opt_general_watch_file_pattern , "" ,
     "Pattern of files to watch out for (to load automatically)"},
 
   { 0, 0 , 0 , "" , 0 }
-- 
GitLab