Example #1
0
 // windows command-line escaping rules are a disaster, partly because how the command-line is 
 // parsed depends on what program you're running.  In windows, the command line is passed in
 // as a single string, and the process is left to interpret it as it sees fit.  The standard
 // C runtime uses one set of rules, the function CommandLineToArgvW usually used by
 // GUI-mode programs uses a different set. 
 // Here we try to find a common denominator that works well for simple cases
 // it's only minimally tested right now due to time constraints.
 fc::string detail::process_impl::windows_shell_escape(const fc::string& str) {
   if (str.find_first_of(" \"") == fc::string::npos)
      return str;
   fc::string escaped_quotes(str);
   for (size_t start = escaped_quotes.find("\"");
        start != fc::string::npos;
        start = escaped_quotes.find("\"", start + 2))
      escaped_quotes.replace(start, 1, "\\\"");
   fc::string escaped_str("\"");
   escaped_str += escaped_quotes;
   escaped_str += "\"";
   return escaped_str;
 }
Example #2
0
 // these rules work pretty well for a standard bash shell on unix
 fc::string detail::process_impl::unix_shell_escape(const fc::string& str) {
   if (str.find_first_of(" ;&|><*?`$(){}[]!#'\"") == fc::string::npos)
      return str;
   fc::string escaped_quotes(str);
   for (size_t start = escaped_quotes.find("'");
        start != fc::string::npos;
        start = escaped_quotes.find("'", start + 5))
      escaped_quotes.replace(start, 1, "'\"'\"'");
   fc::string escaped_str("\'");
   escaped_str += escaped_quotes;
   escaped_str += "\'";
   return escaped_str;
 }