Problem
We've got some code here that logs commit message using git log and then sanitizes the output and turns it to JSON.
This code is fickle, because any symbols included in commit messages that break JSON.parse will cause an error. We've seen a number of instances of this happening over the last year, and it seems likely to continue happening until we nail this code down a bit more robustly.
Solution
- Extract a small module to
src/libs/sanitizeStringForJSON, that escapes special characters from a string to prepare it to be used in JSON.parse
- Use this library in
GitUtils.getMergeLogsAsJSON
- Add a new set of Jest unit tests to cover
sanitizeStringForJSON.
Here are some suggestions to get you started.
Problem
We've got some code here that logs commit message using
git logand then sanitizes the output and turns it to JSON.This code is fickle, because any symbols included in commit messages that break
JSON.parsewill cause an error. We've seen a number of instances of this happening over the last year, and it seems likely to continue happening until we nail this code down a bit more robustly.Solution
src/libs/sanitizeStringForJSON, that escapes special characters from a string to prepare it to be used inJSON.parseGitUtils.getMergeLogsAsJSONsanitizeStringForJSON.Here are some suggestions to get you started.