Skip to content

Commit 563b474

Browse files
committed
TeamCity: Fixed escaping issues.
1 parent 38f058c commit 563b474

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

src/PostSharp.Engineering.BuildTools/ContinuousIntegration/TeamCity/Arguments/BuildConfigurationParameter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ public BuildConfigurationParameter( string name, string value )
1414
this.Value = value;
1515
}
1616

17-
public virtual string GenerateTeamCityCode() => @$" param(""{this.Name}"", ""{this.Value}"")";
17+
public virtual string GenerateTeamCityCode()
18+
=> @$" param(""{KotlinHelper.EscapeString( this.Name )}"", ""{KotlinHelper.EscapeString( this.Value )}"")";
1819
}

src/PostSharp.Engineering.BuildTools/ContinuousIntegration/TeamCity/Arguments/TextBuildConfigurationParameter.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,13 @@ public TextBuildConfigurationParameter( string name, string label, string descri
2121
}
2222

2323
public override string GenerateTeamCityCode()
24-
=> @$" text(""{this.Name}"", ""{this.Value}"", label = ""{this.Label}"", description = ""{this.Description}""{(!this.AllowEmpty ? "" : ", allowEmpty = true")}{(!this.Validation.HasValue ? "" : @$", regex = """"""{this.Validation.Value.Regex}"""""", validationMessage = ""{this.Validation.Value.ValidationMessage}""")})";
24+
=> $"""
25+
text(
26+
"{KotlinHelper.EscapeString( this.Name )}",
27+
"{KotlinHelper.EscapeString( this.Value )}",
28+
label ="{KotlinHelper.EscapeString( this.Label )}",
29+
description = "{KotlinHelper.EscapeString( this.Description )}"{(!this.AllowEmpty ? "" : ", allowEmpty = true")}{(!this.Validation.HasValue ? "" : @$",
30+
regex = """"""{KotlinHelper.EscapeString( this.Validation.Value.Regex )}"""""",
31+
validationMessage = ""{KotlinHelper.EscapeString( this.Validation.Value.ValidationMessage )}""")})
32+
""";
2533
}

src/PostSharp.Engineering.BuildTools/ContinuousIntegration/TeamCity/BuildSteps/PowerShellCommandBuildStep.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public PowerShellCommandBuildStep(
3333
public override string GenerateTeamCityCode()
3434
{
3535
return $@" powerShell {{
36-
name = ""{this.Name}""
36+
name = ""{KotlinHelper.EscapeString( this.Name )}""
3737
id = ""{this.Id}""{(this.WorkingDirectory == null ? "" : $@"
3838
workingDir = ""{this.WorkingDirectory.Replace( Path.DirectorySeparatorChar, '/' )}""")}
3939
scriptMode = script {{
40-
content = ""{this.Command.Replace( "\"", "\"\"", StringComparison.Ordinal )}""
40+
content = ""{KotlinHelper.EscapeString( this.Command )}""
4141
}}
4242
noProfile = false
4343
}}";
4444
}
45-
}
45+
}

src/PostSharp.Engineering.BuildTools/ContinuousIntegration/TeamCity/BuildSteps/PowerShellScriptBuildStep.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ public PowerShellScriptBuildStep(
5858
public override string GenerateTeamCityCode()
5959
{
6060
return $@" powerShell {{
61-
name = ""{this.Name}""
61+
name = ""{KotlinHelper.EscapeString( this.Name )}""
6262
id = ""{this.Id}""{(this.WorkingDirectory == null ? "" : $@"
6363
workingDir = ""{this.WorkingDirectory.Replace( Path.DirectorySeparatorChar, '/' )}""")}
6464
scriptMode = file {{
65-
path = ""{this.ScriptPath}""
65+
path = ""{this.ScriptPath.Replace( Path.DirectorySeparatorChar, '/' )}""
6666
}}
6767
noProfile = false
68-
scriptArgs = ""{this.ScriptArguments}""
68+
scriptArgs = ""{KotlinHelper.EscapeString( this.ScriptArguments )}""
6969
}}";
7070
}
7171
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+
using System;
4+
5+
namespace PostSharp.Engineering.BuildTools.ContinuousIntegration.TeamCity;
6+
7+
internal static class KotlinHelper
8+
{
9+
public static string EscapeString( string value )
10+
{
11+
// Escape for Kotlin string: \ => \\, " => \"
12+
return value
13+
.Replace( "\\", "\\\\", StringComparison.Ordinal )
14+
.Replace( "\"", "\\\"", StringComparison.Ordinal );
15+
}
16+
}

0 commit comments

Comments
 (0)