Skip to content

Commit b30c930

Browse files
authored
[AzureRGDeploy] Stripping comments bug fix (#6184) (#6186)
* stripping comments bug fix * Skipping instead * Removing unused variable
1 parent 7e11479 commit b30c930

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
//This json file has comments
2+
// This json file has comments
3+
"var": "value ending with escaped character\\\"\\\\"
4+
/*some Comment After the escaped Character */
35
}

Tasks/AzureResourceGroupDeployment/operations/ResourceGroup.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ function stripJsonComments(content) {
3939

4040
var currentChar;
4141
var nextChar;
42-
var prevChar;
4342
var insideQuotes = false;
4443
var contentWithoutComments = '';
4544
var insideComment = 0;
@@ -65,21 +64,26 @@ function stripJsonComments(content) {
6564
}
6665

6766
} else {
68-
prevChar = i - 1 >= 0 ? content[i - 1] : "";
69-
70-
if (currentChar == '"' && prevChar != '\\') {
71-
insideQuotes = !insideQuotes
67+
if (insideQuotes && currentChar == "\\") {
68+
contentWithoutComments += currentChar + nextChar;
69+
i++; // Skipping checks for next char if escaped
70+
continue;
7271
}
73-
74-
if (!insideQuotes) {
75-
if (currentChar + nextChar === '//') {
76-
insideComment = singlelineComment;
77-
i++;
72+
else {
73+
if (currentChar == '"') {
74+
insideQuotes = !insideQuotes;
7875
}
7976

80-
if (currentChar + nextChar === '/*') {
81-
insideComment = multilineComment;
82-
i++;
77+
if (!insideQuotes) {
78+
if (currentChar + nextChar === '//') {
79+
insideComment = singlelineComment;
80+
i++;
81+
}
82+
83+
if (currentChar + nextChar === '/*') {
84+
insideComment = multilineComment;
85+
i++;
86+
}
8387
}
8488
}
8589
}

Tasks/AzureResourceGroupDeployment/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 2,
1616
"Minor": 2,
17-
"Patch": 16
17+
"Patch": 17
1818
},
1919
"demands": [],
2020
"minimumAgentVersion": "2.119.1",

Tasks/AzureResourceGroupDeployment/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": 2,
1616
"Minor": 2,
17-
"Patch": 16
17+
"Patch": 17
1818
},
1919
"demands": [],
2020
"minimumAgentVersion": "2.119.1",

0 commit comments

Comments
 (0)