[core] CodeClimateRenderer: corrupt JSON output with real line breaks
A source code analyzer
Brought to you by:
adangel,
juansotuyo
When using code climate output with XPath rules, then the "content/body" property contains a very long string and eventually also the XPath expression of the rule. However, the XPath expression might contain line breaks, which are not escaped in the output... hence creating a corrupt JSON file.
Corrupt example:
{"type":"issue","check_name":"CollapsibleIfStatements","description":"These nested if statements could be combined","content":{"body":"## CollapsibleIfStatements\n\nSince: PMD 3.1\n\nPriority: Medium\n\n[Categories](https://github.com/codeclimate/spec/blob/master/SPEC.md#categories): Style\n\n[Remediation Points](https://github.com/codeclimate/spec/blob/master/SPEC.md#remediation-points): 50000\n\nSometimes two consecutive `if` statements can be consolidated by separating their conditions with a boolean short-circuit operator.\n\n### Example:\n\n```java\n\n \nvoid bar() {\n\tif (x) {\t\t\t// original implementation\n\t\tif (y) {\n\t\t\t// do stuff\n\t\t}\n\t}\n}\n\nvoid bar() {\n\tif (x && y) {\t\t// optimized implementation\n\t\t// do stuff\n\t}\n}\n \n \n``` \n\n### [PMD properties](http://pmd.github.io/pmd-5.1.3/pmd-developer.html)\n\nName | Value | Description\n--- | --- | ---\nviolationSuppressRegex | null | Suppress violations with messages matching a regular expression\nviolationSuppressXPath | null | Suppress violations on nodes which match a given relative XPath expression.\nversion | 1.0 | XPath specification version\nxpath | //IfStatement[@Else='false']/Statement /IfStatement[@Else='false'] | //IfStatement[@Else='false']/Statement /Block[count(BlockStatement)=1]/BlockStatement /Statement/IfStatement[@Else='false'] | XPath expression\n"},"categories":["Style"],"location":{"path":"/home/andreas/PMD/source/pmd-github/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java","lines":{"begin":617,"end":619}},"severity":"normal","remediation_points":50000}
See also: https://github.com/pmd/pmd/pull/96
This will be fixed with PMD 5.5.0
Commit: https://github.com/pmd/pmd/commit/8a9bccb583b5b28539dd0ba333f57bebfae9f1a6 and https://github.com/pmd/pmd/commit/efdcbfe10973bd859db1b53734a6996e6858ace7