Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit msbuild escaped characters to the minimum #2394

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/app/Fake.DotNet.MSBuild/MSBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -501,19 +501,21 @@ module MSBuild =
| [] -> None
| t -> Some("t", t |> Seq.map (String.replace "." "_") |> String.separated ";")

// see https://github.com/fsharp/FAKE/issues/2112
let escapePropertyValue (v:string) =
// https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-special-characters?view=vs-2017
// This list has been found by trial and error but isn't perfect.
//
// Neither escaping everything (breaks <UsingTask AssemblyFile="$(Path)"" />)
// nor only what's documented by Microsoft at https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-special-characters?view=vs-2017
// (same problem with paths and ',' isn't covered but is still required to escape) works.
//
// This escape isn't perfect, mainly passing a a parameter with a ',' inside to a part of
// msbuild that doesn't support '%' escaping doesn't work but it's good for 99% of use cases.
//
// See https://github.com/fsharp/FAKE/issues/2112 and https://github.com/fsharp/FAKE/issues/2392
// for some history on this problem
v.Replace("%", "%25")
.Replace("\\", "%5C")
.Replace("\"", "%22")
.Replace(";", "%3B")
.Replace(",", "%2C")
.Replace("$", "%24")
.Replace("@", "%40")
.Replace("'", "%27")
.Replace("?", "%3F")
.Replace("*", "%2A")

let properties =
p.Properties
Expand Down
8 changes: 4 additions & 4 deletions src/test/Fake.Core.UnitTests/Fake.DotNet.MSBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ let tests =
ConsoleLogParameters = []
Properties = ["OutputPath", "C:\\Test\\"] })
let expected =
if Environment.isUnix then "/p:RestorePackages=False /p:OutputPath=C:%5CTest%5C"
else "/m /nodeReuse:False /p:RestorePackages=False /p:OutputPath=C:%5CTest%5C"
if Environment.isUnix then "/p:RestorePackages=False /p:OutputPath=C:\\Test\\"
else "/m /nodeReuse:False /p:RestorePackages=False /p:OutputPath=C:\\Test\\"
Expect.equal cmdLine expected "Expected a given cmdline."
testCase "Test that /restore is included #2160" <| fun _ ->
let _, cmdLine =
Expand All @@ -24,7 +24,7 @@ let tests =
ConsoleLogParameters = []
DoRestore = true })
let expected =
if Environment.isUnix then "/restore /p:RestorePackages=False"
else "/restore /m /nodeReuse:False /p:RestorePackages=False"
if Environment.isUnix then "/restore /p:RestorePackages=False"
else "/restore /m /nodeReuse:False /p:RestorePackages=False"
Expect.equal cmdLine expected "Expected a given cmdline."
]