Skip to content

Commit

Permalink
Escaping block character for file match (#11791)
Browse files Browse the repository at this point in the history
* Escaping block character for file match

* Addressed review comments

* Updated task version
  • Loading branch information
vinodkumar3 authored Nov 28, 2019
1 parent 3546d7d commit aeabd3a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
10 changes: 7 additions & 3 deletions Tasks/AzureResourceGroupDeploymentV2/operations/ResourceGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export class ResourceGroup {
private createDeploymentName(): string {
var name: string;
if (this.taskParameters.templateLocation == "Linked artifact") {
name = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), this.taskParameters.csmFile)[0];
name = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), this.escapeBlockCharacters(this.taskParameters.csmFile))[0];
} else {
name = this.taskParameters.csmFileLink;
}
Expand Down Expand Up @@ -382,7 +382,7 @@ export class ResourceGroup {

private getDeploymentDataForLinkedArtifact(): Deployment {
var template: TemplateObject;
var fileMatches = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), this.taskParameters.csmFile);
var fileMatches = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), this.escapeBlockCharacters(this.taskParameters.csmFile));
if (fileMatches.length > 1) {
throw new Error(tl.loc("TemplateFilePatternMatchingMoreThanOneFile", fileMatches));
}
Expand All @@ -405,7 +405,7 @@ export class ResourceGroup {

var parameters: Map<string, ParameterValue> = {} as Map<string, ParameterValue>;
if (utils.isNonEmpty(this.taskParameters.csmParametersFile)) {
var fileMatches = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), this.taskParameters.csmParametersFile);
var fileMatches = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), this.escapeBlockCharacters(this.taskParameters.csmParametersFile));
if (fileMatches.length > 1) {
throw new Error(tl.loc("TemplateParameterFilePatternMatchingMoreThanOneFile", fileMatches));
}
Expand Down Expand Up @@ -569,6 +569,10 @@ export class ResourceGroup {
await this.performAzureDeployment(armClient, deployment, 3);
}

private escapeBlockCharacters(str: string): string {
return str.replace(/[\[]/g, '$&[]');
}

private enablePrereqDG = "ConfigureVMWithDGAgent";
private enablePrereqWinRM = "ConfigureVMwithWinRM";
private enablePrereqNone = "None";
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureResourceGroupDeploymentV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 2,
"Minor": 157,
"Patch": 7
"Patch": 8
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/AzureResourceGroupDeploymentV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 2,
"Minor": 157,
"Patch": 7
"Patch": 8
},
"demands": [],
"minimumAgentVersion": "2.119.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class Utils {
public static createDeploymentName(taskParameters: armDeployTaskParameters.TaskParameters): string {
var name: string;
if (taskParameters.templateLocation == "Linked artifact") {
name = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), taskParameters.csmFile)[0];
name = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), this.escapeBlockCharacters(taskParameters.csmFile))[0];
} else {
name = taskParameters.csmFileLink;
}
Expand All @@ -224,7 +224,7 @@ class Utils {

public static getDeploymentDataForLinkedArtifact(taskParameters: armDeployTaskParameters.TaskParameters): DeploymentParameters {
var template: TemplateObject;
var fileMatches = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), taskParameters.csmFile);
var fileMatches = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), this.escapeBlockCharacters(taskParameters.csmFile));
if (fileMatches.length > 1) {
throw new Error(tl.loc("TemplateFilePatternMatchingMoreThanOneFile", fileMatches));
}
Expand All @@ -247,7 +247,7 @@ class Utils {

var parameters: Map<string, ParameterValue> = {} as Map<string, ParameterValue>;
if (this.isNonEmpty(taskParameters.csmParametersFile)) {
var fileMatches = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), taskParameters.csmParametersFile);
var fileMatches = tl.findMatch(tl.getVariable("System.DefaultWorkingDirectory"), this.escapeBlockCharacters(taskParameters.csmParametersFile));
if (fileMatches.length > 1) {
throw new Error(tl.loc("TemplateParameterFilePatternMatchingMoreThanOneFile", fileMatches));
}
Expand Down Expand Up @@ -403,6 +403,10 @@ class Utils {

return result;
}

private static escapeBlockCharacters(str: string): string {
return str.replace(/[\[]/g, '$&[]');
}
}

export = Utils;
2 changes: 1 addition & 1 deletion Tasks/AzureResourceManagerTemplateDeploymentV3/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 3,
"Minor": 1,
"Patch": 4
"Patch": 5
},
"preview": "true",
"demands": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"version": {
"Major": 3,
"Minor": 1,
"Patch": 4
"Patch": 5
},
"preview": "true",
"demands": [],
Expand Down

0 comments on commit aeabd3a

Please sign in to comment.