]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/process/detail/windows/basic_cmd.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / process / detail / windows / basic_cmd.hpp
index fdd0b94469438e17dfd163edf29a586a53883b46..53ea9931d1a86614cbbaec7cc23378de01caee15 100644 (file)
@@ -30,14 +30,17 @@ inline std::string build_args(const std::string & exe, std::vector<std::string>
 {
     std::string st = exe;
 
-    //put in quotes if it has spaces
+    //put in quotes if it has spaces or double quotes
+    if(!exe.empty())
     {
-        boost::replace_all(st, "\"", "\\\"");
+        auto it = st.find_first_of(" \"");
 
-        auto it = std::find(st.begin(), st.end(), ' ');
-
-        if (it != st.end())//contains spaces.
+        if(it != st.npos)//contains spaces.
         {
+            // double existing quotes
+            boost::replace_all(st, "\"", "\"\"");
+
+            // surround with quotes
             st.insert(st.begin(), '"');
             st += '"';
         }
@@ -45,15 +48,18 @@ inline std::string build_args(const std::string & exe, std::vector<std::string>
 
     for (auto & arg : data)
     {
-        boost::replace_all(arg, "\"", "\\\"");
-
-        auto it = std::find(arg.begin(), arg.end(), ' ');//contains space?
-        if (it != arg.end())//ok, contains spaces.
+        if(!arg.empty())
         {
-            //the first one is put directly onto the output,
-            //because then I don't have to copy the whole string
-            arg.insert(arg.begin(), '"');
-            arg += '"'; //thats the post one.
+            auto it = arg.find_first_of(" \"");//contains space or double quotes?
+            if(it != arg.npos)//yes
+            {
+                // double existing quotes
+                boost::replace_all(arg, "\"", "\"\"");
+
+                // surround with quotes
+                arg.insert(arg.begin(), '"');
+                arg += '"';
+            }
         }
 
         if (!st.empty())//first one does not need a preceeding space
@@ -68,30 +74,36 @@ inline std::wstring build_args(const std::wstring & exe, std::vector<std::wstrin
 {
     std::wstring st = exe;
 
-    //put in quotes if it has spaces
+    //put in quotes if it has spaces or double quotes
+    if(!exe.empty())
     {
-        boost::replace_all(st, L"\"", L"\\\"");
-
-        auto it = std::find(st.begin(), st.end(), L' ');
+        auto it = st.find_first_of(L" \"");
 
-        if (it != st.end())//contains spaces.
+        if(it != st.npos)//contains spaces or double quotes.
         {
+            // double existing quotes
+            boost::replace_all(st, L"\"", L"\"\"");
+
+            // surround with quotes
             st.insert(st.begin(), L'"');
             st += L'"';
         }
     }
 
-    for (auto & arg : data)
+    for(auto & arg : data)
     {
-        boost::replace_all(arg, L"\"", L"\\\"");
-
-        auto it = std::find(arg.begin(), arg.end(), L' ');//contains space?
-        if (it != arg.end())//ok, contains spaces.
+        if(!arg.empty())
         {
-            //the first one is put directly onto the output,
-            //because then I don't have to copy the whole string
-            arg.insert(arg.begin(), L'"');
-            arg += L'"'; //thats the post one.
+            auto it = arg.find_first_of(L" \"");//contains space or double quotes?
+            if(it != arg.npos)//yes
+            {
+                // double existing quotes
+                boost::replace_all(arg, L"\"", L"\"\"");
+
+                // surround with quotes
+                arg.insert(arg.begin(), L'"');
+                arg += '"';
+            }
         }
 
         if (!st.empty())//first one does not need a preceeding space