Skip to content

Commit

Permalink
proper quotation in Process.fs
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed Aug 5, 2018
1 parent d62ff0a commit 109ec13
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/app/Fake.Core.Process/Process.fs
Original file line number Diff line number Diff line change
Expand Up @@ -536,14 +536,16 @@ module Process =

/// Adds quotes around the string
/// [omit]
let quote (str:string) = "\"" + str.Replace("\"","\\\"") + "\""
let quote (str:string) =
// "\"" + str.Replace("\"","\\\"") + "\""
CmdLineParsing.windowsArgvToCommandLine [ str ]

/// Adds quotes around the string if needed
/// [omit]
let quoteIfNeeded str =
if String.isNullOrEmpty str then ""
elif str.Contains " " then quote str
else str
let quoteIfNeeded str = quote str
//if String.isNullOrEmpty str then ""
//elif str.Contains " " then quote str
//else str

/// Adds quotes and a blank around the string´.
/// [omit]
Expand All @@ -556,15 +558,15 @@ module Process =
/// [omit]
let stringParam (paramName, paramValue) =
if String.isNullOrEmpty paramValue then None
else Some(paramName, quote paramValue)
else Some(paramName, paramValue)

/// [omit]
let multipleStringParams paramName = Seq.map (fun x -> stringParam (paramName, x)) >> Seq.toList

/// [omit]
let optionParam (paramName, paramValue) =
match paramValue with
| Some x -> Some(paramName, x.ToString() |> quote)
| Some x -> Some(paramName, x.ToString())
| None -> None

/// [omit]
Expand All @@ -576,10 +578,14 @@ module Process =
let parametersToString flagPrefix delimiter parameters =
parameters
|> Seq.choose id
|> Seq.map (fun (paramName, paramValue) ->
flagPrefix + paramName + if String.isNullOrEmpty paramValue then ""
else delimiter + paramValue)
|> String.separated " "
|> Seq.collect (fun (paramName, paramValue) ->
if String.isNullOrEmpty paramValue || delimiter <> " " then
[ flagPrefix + paramName + if String.isNullOrEmpty paramValue then ""
else delimiter + paramValue ]
else
[ flagPrefix + paramName
paramValue ])
|> CmdLineParsing.windowsArgvToCommandLine

/// Searches the given directories for all occurrences of the given file name
/// [omit]
Expand Down Expand Up @@ -684,8 +690,8 @@ module Process =
if String.isLetterOrDigit (str.Chars(str.Length - 1)) then str + " "
else str
args
|> Seq.map (fun (k, v) -> delimit k + quoteIfNeeded v)
|> String.separated " "
|> Seq.collect (fun (k, v) -> [ delimit k; v ])
|> CmdLineParsing.windowsArgvToCommandLine

/// Execute an external program asynchronously and return the exit code,
/// logging output and error messages to FAKE output. You can compose the result
Expand Down

0 comments on commit 109ec13

Please sign in to comment.