private static string QuotePropertyValue(string arg)
        {
            if (!IsPropertyArgument(arg))
            {
                return(arg);
            }

            var parts = arg.Split(new[] { '=' }, 2);

            if (parts.Length != 2)
            {
                return(arg);
            }

            // Escaping `://` is a workaround for https://github.com/Microsoft/msbuild/issues/1622
            // The issue is that MSBuild is collapsing multiple slashes to a single slash due to a bad regex.
            var value = parts[1].Replace("://", ":%2f%2f");

            if (ArgumentEscaper.IsSurroundedWithQuotes(value))
            {
                return($"{parts[0]}={value}");
            }

            return($"{parts[0]}={ArgumentEscaper.EscapeSingleArg(value, forceQuotes: true)}");
        }
Пример #2
0
        private CommandSpec CreateCommandSpecWrappedWithCmd(
            string command,
            IEnumerable <string> args)
        {
            var comSpec = Environment.GetEnvironmentVariable("ComSpec") ?? "cmd.exe";

            // Handle the case where ComSpec is already the command
            if (command.Equals(comSpec, StringComparison.OrdinalIgnoreCase))
            {
                command = args.FirstOrDefault();
                args    = args.Skip(1);
            }

            var cmdEscapedArgs = ArgumentEscaper.EscapeAndConcatenateArgArrayForCmdProcessStart(args);

            if (!ArgumentEscaper.IsSurroundedWithQuotes(command) && // Don't quote already quoted strings
                ArgumentEscaper.ShouldSurroundWithQuotes(command))
            {
                command = $"\"{command}\"";
            }

            var escapedArgString = $"/s /c \"{command} {cmdEscapedArgs}\"";

            return(new CommandSpec(comSpec, escapedArgString));
        }