Skip to content

Commit

Permalink
Merge pull request #13644 from Expensify/chirag-deploy-fix-5
Browse files Browse the repository at this point in the history
[No QA] Escaping all instances backslash
  • Loading branch information
luacmartins committed Dec 15, 2022
2 parents 18983f8 + 1c9b81b commit e4daa15
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,13 @@ function getMergeLogsAsJSON(fromRef, toRef) {
})
.then((stdout) => {
// Remove any double-quotes from commit subjects
console.log(`[debug] stdOut: ${stdout}`);
let sanitizedOutput = stdout.replace(/(?<="subject": ").*(?="})/g, subject => subject.replace(/"/g, "'"));
console.log(`[debug] sanitizedOutput 1: ${sanitizedOutput}`);

// Also remove any newlines and escape backslashes
sanitizedOutput = sanitizedOutput.replace(/(\r\n|\n|\r)/gm, '').replace('\\', '\\\\');
console.log(`[debug] sanitizedOutput 2: ${sanitizedOutput}`);
sanitizedOutput = sanitizedOutput.replace(/(\r\n|\n|\r)/gm, '').replace(/\\/g, '\\\\');

// Then format as JSON and convert to a proper JS object
const json = `[${sanitizedOutput}]`.replace('},]', '}]');
console.log(`[debug] json: ${json}`);

return JSON.parse(json);
});
Expand Down
6 changes: 1 addition & 5 deletions .github/actions/javascript/getDeployPullRequestList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,13 @@ function getMergeLogsAsJSON(fromRef, toRef) {
})
.then((stdout) => {
// Remove any double-quotes from commit subjects
console.log(`[debug] stdOut: ${stdout}`);
let sanitizedOutput = stdout.replace(/(?<="subject": ").*(?="})/g, subject => subject.replace(/"/g, "'"));
console.log(`[debug] sanitizedOutput 1: ${sanitizedOutput}`);

// Also remove any newlines and escape backslashes
sanitizedOutput = sanitizedOutput.replace(/(\r\n|\n|\r)/gm, '').replace('\\', '\\\\');
console.log(`[debug] sanitizedOutput 2: ${sanitizedOutput}`);
sanitizedOutput = sanitizedOutput.replace(/(\r\n|\n|\r)/gm, '').replace(/\\/g, '\\\\');

// Then format as JSON and convert to a proper JS object
const json = `[${sanitizedOutput}]`.replace('},]', '}]');
console.log(`[debug] json: ${json}`);

return JSON.parse(json);
});
Expand Down
6 changes: 1 addition & 5 deletions .github/libs/GitUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,13 @@ function getMergeLogsAsJSON(fromRef, toRef) {
})
.then((stdout) => {
// Remove any double-quotes from commit subjects
console.log(`[debug] stdOut: ${stdout}`);
let sanitizedOutput = stdout.replace(/(?<="subject": ").*(?="})/g, subject => subject.replace(/"/g, "'"));
console.log(`[debug] sanitizedOutput 1: ${sanitizedOutput}`);

// Also remove any newlines and escape backslashes
sanitizedOutput = sanitizedOutput.replace(/(\r\n|\n|\r)/gm, '').replace('\\', '\\\\');
console.log(`[debug] sanitizedOutput 2: ${sanitizedOutput}`);
sanitizedOutput = sanitizedOutput.replace(/(\r\n|\n|\r)/gm, '').replace(/\\/g, '\\\\');

// Then format as JSON and convert to a proper JS object
const json = `[${sanitizedOutput}]`.replace('},]', '}]');
console.log(`[debug] json: ${json}`);

return JSON.parse(json);
});
Expand Down

0 comments on commit e4daa15

Please sign in to comment.