sdk/dotnet/Helm/ChartBase.cs
/// <summary>
/// Convert argument to an argument string for using with Process.StartInfo.Arguments.
/// </summary>
Convert argument to an argument string for using with Process.StartInfo.Arguments.
Convert argument to an argument string for using with Process . StartInfo . Arguments .
private static string EscapeArguments(string argument)
        {
            var escapedArgument = new StringBuilder();
            var backslashCount = 0;
            var needsQuotes = false;
            foreach (var character in argument)
            {
                switch (character)
                {
                    case '\\':
                        backslashCount++;
                        escapedArgument.Append('\\');
                        break;
                    case '\"':
                        escapedArgument.Append('\\', backslashCount);
                        escapedArgument.Append("\\\"");
                        backslashCount = 0;
                        break;
                    case ' ':
                    case '\t':
                        needsQuotes = true;
                        escapedArgument.Append(character);
                        backslashCount = 0;
                        break;
                    default:
                        backslashCount = 0;
                        escapedArgument.Append(character);
                        break;
                }
            }
            if (!needsQuotes)
            {
                return escapedArgument.ToString();
            }
            escapedArgument.Insert(0, '"');
             before appending the "
            escapedArgument.Append('\\', backslashCount);
            escapedArgument.Append('\"');
            return escapedArgument.ToString();
        }
private static string EscapeArguments ( string argument ) { var escapedArgument = new StringBuilder ( ) ; var backslashCount = 0 ; var needsQuotes = false ; foreach ( var character in argument ) { switch ( character ) { case ' \\ ' : backslashCount ++ ; escapedArgument . Append ( ' \\ ' ) ; break ; case ' \" ' : escapedArgument . Append ( ' \\ ' , backslashCount ) ; escapedArgument . Append ( " \\ \" " ) ; backslashCount = 0 ; break ; case ' ' : case ' \t ' : needsQuotes = true ; escapedArgument . Append ( character ) ; backslashCount = 0 ; break ; default : backslashCount = 0 ; escapedArgument . Append ( character ) ; break ; } } if ( ! needsQuotes ) { return escapedArgument . ToString ( ) ; } escapedArgument . Insert ( 0 , ' ' ) ; escapedArgument . Append ( ' \\ ' , backslashCount ) ; escapedArgument . Append ( ' \" ' ) ; return escapedArgument . ToString ( ) ; }
Convert argument to an argument string for using with Process.StartInfo.Arguments.
Convert argument to an argument string for using with Process . StartInfo . Arguments .
// Backslashes are simply passed through, except when they need // to be escaped when followed by a \", e.g. the argument string // \", which would be encoded to \\\" // Escape any preceding backslashes // Append an escaped double quote. // Reset the backslash counter. // White spaces are escaped by surrounding the entire string with // double quotes, which should be done at the end to prevent // multiple wrappings. // Append the whitespace // Reset the backslash counter. // Reset the backslash counter. // Append the current character // No need to wrap in quotes // Prepend the " // Escape any preceding backslashes before appending the " // Append the final "
argument
string