PMD: pmd-format results in jq parsing errors
Summary
The pmd-format job results in a jq parsing errors because of invalid escape characters in the JSON data
Steps to reproduce
Run the scan against a Java project
What is the current bug behavior?
jq parsing errors like: jq: parse error: Invalid escape at line 1, column 3008
What is the expected correct behavior?
No jq parsing errors.
Relevant logs and/or screenshots
Possible fixes
script:
- |
# Check if the file exists
if [ -f gl-code-quality-not-formatted.json ]; then
# Fix potential escape character issues before processing with jq
# Replace problematic escape sequences and then process with jq
cat gl-code-quality-not-formatted.json | sed 's/\\[^"\/bfnrtu]/\\\\&/g' > sanitized-output.json
# Process the sanitized file
jq '[.[] | . + {fingerprint: (.location.path + ":" + (.location.lines.begin|tostring) + ":" + .description | @md5)}]' sanitized-output.json > gl-code-quality-report.json || echo "[]" > gl-code-quality-report.json
else
# Create an empty array if the input file doesn't exist
echo "[]" > gl-code-quality-report.json
fi
Edited by Norman Debald
