Skip to content

Conversation

pfrenssen
Copy link
Contributor

When any of the error or warning messages contain tabs or newlines and a JSON report is generated then the resulting JSON will be invalid.

A good solution for this would be to use json_encode() to generate the JSON, but since we need to support old PHP versions this is not possible until PHP CodeSniffer 3 (see #449 for more information).

For the moment we can work around the issue by replacing the offending characters before outputting the JSON report.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also add \r to the list for Windows users.

@pfrenssen
Copy link
Contributor Author

@aik099 great suggestion, thanks!

I have added a line that converts carriage returns to the harmless '\r' character sequence.

@gsherwood gsherwood changed the title Prevent generating invalid json reports when messages contain newlines or tabs JSON report is invalid when messages contain newlines or tabs Oct 11, 2015
@gsherwood gsherwood merged commit fed10fc into squizlabs:master Oct 11, 2015
@gsherwood
Copy link
Member

Thanks a lot for the fix.

jrfnl added a commit to jrfnl/PHP_CodeSniffer that referenced this pull request Nov 23, 2024
…rs-add-tests-documentation-titles Generators: add tests for handling documentation titles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants