From 8caec83b074121fb94e21f416b9e20bc7a4605c8 Mon Sep 17 00:00:00 2001 From: Owen Stephens Date: Wed, 24 Jun 2020 09:29:16 +0100 Subject: [PATCH] [Fix #8205] Avoid false positive in Style/RedundantRegexpCharacterClass If the first element of a character class was an escaped-] our pattern was treating it as a single element classs containing a single backslash (which is invalid, and incorrect). --- CHANGELOG.md | 1 + .../style/redundant_regexp_character_class.rb | 1 + .../redundant_regexp_character_class_spec.rb | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04a1b0ac779..6afb6f8eb1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ * [#8195](https://github.com/rubocop-hq/rubocop/issues/8195): Fix an error for `Style/RedundantFetchBlock` when using `#fetch` with empty block. ([@koic][]) * [#8193](https://github.com/rubocop-hq/rubocop/issues/8193): Fix a false positive for `Style/RedundantRegexpCharacterClass` when using `[\b]`. ([@owst][]) +* [#8205](https://github.com/rubocop-hq/rubocop/issues/8205): Fix a false positive for `Style/RedundantRegexpCharacterClass` when using a leading escaped `]`. ([@owst][]) ## 0.86.0 (2020-06-22) diff --git a/lib/rubocop/cop/style/redundant_regexp_character_class.rb b/lib/rubocop/cop/style/redundant_regexp_character_class.rb index 80c605c53bc..671afd0fcb1 100644 --- a/lib/rubocop/cop/style/redundant_regexp_character_class.rb +++ b/lib/rubocop/cop/style/redundant_regexp_character_class.rb @@ -38,6 +38,7 @@ class RedundantRegexpCharacterClass < Cop [^.*+?{}()|$] | # or one that doesn't require escaping outside the character class \\[upP]\{[^}]+\} # or a unicode code-point or property ) + (?