Wrap command argument in quotes and escape when this contains special characters.
556667
def wrap_argument(text):
    
    if not any(x in text for x in [' ', '"', "'", '\\']):
        return text
    else:
        return '"%s"' % (text.replace('\\', r'\\').replace('"', r'\"'), )
809876
function escapeShellArg(value) {
    if (is.number(value)) {
        return value;
    }

    value = String(value);
    value = value.replace(/"/g, '\\"');

    return '"' + value + '"';
}
1199111
def quote(value):
    
    if value == None:
        output = ""
    elif is_text(value):
        output = encode_basestring(value)
    else:
        output = _json.dumps(value)
    return output
1173429
private static List<String> fixArguments(List<String> command) {
    if (!IS_OS_WINDOWS) {
      return command;
    }
    List<String> result = new ArrayList<String>(command);
    for (ListIterator it = result.listIterator(); it.hasNext(); ) {
      if ("".equals(it.next())) {
        it.set("\"\"");
      }
    }
    return result;
  }
200757
def quote_plus(string, safe='', encoding=None, errors=None):
    
    # Check if ' ' in string, where string may either be a str or bytes.  If
    # there are no spaces, the regular quote will produce the right answer.
    if ((isinstance(string, str) and ' ' not in string) or
        (isinstance(string, bytes) and b' ' not in string)):
        return quote(string, safe, encoding, errors)
    if isinstance(safe, str):
        space = str(' ')
    else:
        space = bytes(b' ')
    string = quote(string, safe + space, encoding, errors)
    return string.replace(' ', '+')
106827
def escape_header(val):
    """"""

    if val is None:
        return None
    try:
        return quote(val, encoding="ascii", safe="/ ")
    except ValueError:
        return "utf-8''" + quote(val, encoding="utf-8", safe="/ ")
164436
function(command) {
        var patt = /("[^"]*")/,
            quotedStringPlaceholder = "__QUOTEDSTR__",
            escapedQuotePlaceholder = "__ESCAPED_QUOTE__",
            matches = [],
            match;

        command = command.replace(/\\\"/g, escapedQuotePlaceholder);

        while ((match = patt.exec(command))) {
            var matched = match[0];
            command =
                command.substr(0, match.index) + quotedStringPlaceholder + command.substr(match.index + matched.length);
            matches.push(matched.substring(1, matched.length - 1));
        }

        var parts = command.split(" ");
        parts = parts.map(function(part) {
            var item = part.trim();
            if (item === quotedStringPlaceholder) {
                item = matches.shift();
            }
            item = item.replace(new RegExp(escapedQuotePlaceholder, "g"), '"');
            return item;
        });

        return parts;
    }
907077
def quoted(text):
    
    if text and " " in text:
        sep = "'" if '"' in text else '"'
        return "%s%s%s" % (sep, text, sep)
    return text
1012319
def escape(self, obj):
        '''   '''
        if isinstance(obj, str_type):
            return "'" + self.escape_string(obj) + "'"
        return escape_item(obj, self.charset)
902500
public static function escapeArguments(array $arguments, $command = null)
    {
        $processedArguments = array();
        foreach ($arguments as $key => $value) {
            if (is_string($key) && substr($key, 0, 1) === '-') {
                if (is_array($value) === false) {
                    $value = array($value);
                }

                foreach ($value as $optionValue) {
                    if ($optionValue === null) {
                        $processedArguments[] = $key;
                    } elseif (is_string($optionValue)) {
                        $processedArguments[] = trim(sprintf('%s=%s', $key, $optionValue));
                    }
                }
            } elseif (is_scalar($value)) {
                $processedArguments[] = $value;
            }
        }

        if ($command !== null) {
            array_unshift($processedArguments, $command);
        }

        return implode(' ', array_map(array(__CLASS__, 'escapeArgument'), $processedArguments));
    }
148202
def escape_grouped_arguments(s):
    
    if s is None:
        return None

    # Additional escaping for windows paths
    if os.name == "nt":
        s = "{}".format(s.replace("\\", "\\\\"))
    return '"' + s.replace("'", "'\\''") + '"'
863046
function escapeValue(value) {
        switch (options.type) {
        case 'js':
            return value.replace(/'/g, '\\\'');
        case 'json':
            return value.replace(/"/g, '\\"');
        default:
            return value;
        }
    }
1164687
def cmdvalu(self, until=cmdquote):
        '''
        
        '''
        self.ignore(whitespace)
        if self.nextstr('"'):
            return self.quoted()
        if self.nextstr("'"):
            return self.singlequoted()
        return self.noms(until=until)
183597
def escape(str):
    """"""
    out = ''
    for char in str:
        if char in '\\ ':
            out += '\\'
        out += char
    return out
831
def escape(self, text, quote = True):
        
        if isinstance(text, bytes):
            return escape_b(text, quote)
        else:
            return escape(text, quote)
89305
function(contents, quoteChar, indentString, htmlmin) {
  var content = contents;

  if(Object.keys(htmlmin).length) {
    try{
      content = minify(content, htmlmin);
    } catch(err) {
      gutil.log(filepath + '\n' + err);
    }
  }

  return escapeContent(content, quoteChar, indentString);
}
1083978
def _format_arguments(ctx):
    """"""
    params = [x for x in ctx.command.params if isinstance(x, click.Argument)]

    for param in params:
        for line in _format_argument(param):
            yield line
        yield ''