From 3c51bfa8b2d953415c5e52c2cbb11c2e4c8c1c9c Mon Sep 17 00:00:00 2001 From: Claudiu Popa Date: Thu, 28 Feb 2019 17:18:00 +0100 Subject: [PATCH] Pass `quote=False` to `html.escape` in the JSON reporter Close #2769 --- ChangeLog | 9 ++++++++ pylint/reporters/json.py | 3 +-- pylint/test/regrtest_data/unused_variable.py | 6 ++++++ pylint/test/test_self.py | 22 ++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 pylint/test/regrtest_data/unused_variable.py diff --git a/ChangeLog b/ChangeLog index 0d6813ebdb..320c15e2f5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,15 @@ Pylint's ChangeLog ------------------ +What's New in Pylint 2.3.1? +=========================== + +Release date: TBA + +* Properly pass `quote=False` to `html.escape` in the JSON reporter + + Close #2769 + What's New in Pylint 2.3.0? =========================== diff --git a/pylint/reporters/json.py b/pylint/reporters/json.py index 100ed52648..18d46bd8f1 100644 --- a/pylint/reporters/json.py +++ b/pylint/reporters/json.py @@ -39,8 +39,7 @@ def handle_message(self, msg): "column": msg.column, "path": msg.path, "symbol": msg.symbol, - # pylint: disable=deprecated-method; deprecated since 3.2. - "message": html.escape(msg.msg or ""), + "message": html.escape(msg.msg or "", quote=False), "message-id": msg.msg_id, } ) diff --git a/pylint/test/regrtest_data/unused_variable.py b/pylint/test/regrtest_data/unused_variable.py new file mode 100644 index 0000000000..eee909d531 --- /dev/null +++ b/pylint/test/regrtest_data/unused_variable.py @@ -0,0 +1,6 @@ +# pylint: disable=missing-docstring + +def test(): + variable = '' + variable2 = None + return variable2 diff --git a/pylint/test/test_self.py b/pylint/test/test_self.py index 2c3907e052..d03566eebf 100644 --- a/pylint/test/test_self.py +++ b/pylint/test/test_self.py @@ -433,6 +433,28 @@ def test_json_report_when_file_is_missing(self): assert message[key] == value assert message["message"].startswith("No module named") + def test_json_report_does_not_escape_quotes(self): + out = StringIO() + module = join(HERE, "regrtest_data", "unused_variable.py") + self._runtest([module], code=4, reporter=JSONReporter(out)) + output = json.loads(out.getvalue()) + assert isinstance(output, list) + assert len(output) == 1 + assert isinstance(output[0], dict) + expected = { + "symbol": "unused-variable", + "module": "unused_variable", + "column": 4, + "message": "Unused variable 'variable'", + "message-id": "W0612", + "line": 4, + "type": "warning", + } + message = output[0] + for key, value in expected.items(): + assert key in message + assert message[key] == value + def test_information_category_disabled_by_default(self): expected = "Your code has been rated at 10.00/10" path = join(HERE, "regrtest_data", "meta.py")