Skip to content

Commit

Permalink
Escape special symbols and newlines in messages. (#9164) (#9165)
Browse files Browse the repository at this point in the history
(cherry picked from commit df0800e)

Co-authored-by: theirix <[email protected]>
  • Loading branch information
github-actions[bot] and theirix authored Oct 18, 2023
1 parent 759e2cc commit 792da24
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/7874.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Escape special symbols and newlines in messages.

Closes #7874
4 changes: 2 additions & 2 deletions pylint/extensions/magic_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def _check_constants_comparison(self, node: nodes.Compare) -> None:

operand_value = None
if const_operands[LEFT_OPERAND] and self._is_magic_value(left_operand):
operand_value = left_operand.value
operand_value = left_operand.as_string()
elif const_operands[RIGHT_OPERAND] and self._is_magic_value(right_operand):
operand_value = right_operand.value
operand_value = right_operand.as_string()
if operand_value is not None:
self.add_message(
"magic-value-comparison",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ class Christmas(Enum):

shouldnt_raise = var == '\n'
shouldnt_raise = var == '\\b'

should_escape = var == "foo\nbar" # [magic-value-comparison]
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ comparison-of-constants:24:17:24:22::"Comparison between constants: '5 > 7' has
singleton-comparison:29:17:29:28::Comparison 'var == True' should be 'var is True' if checking for the singleton value True, or 'bool(var)' if testing for truthiness:UNDEFINED
singleton-comparison:30:17:30:29::Comparison 'var == False' should be 'var is False' if checking for the singleton value False, or 'not var' if testing for falsiness:UNDEFINED
singleton-comparison:31:17:31:28::Comparison 'var == None' should be 'var is None':UNDEFINED
magic-value-comparison:38:16:38:33::Consider using a named constant or an enum instead of ''foo\nbar''.:HIGH

0 comments on commit 792da24

Please sign in to comment.