Skip to content

Commit

Permalink
Add forward slash to LITERAL_REGEX
Browse files Browse the repository at this point in the history
The forward slash character has no special meaning when it appears in a
regex. This will let `Performance/StartWith` and `Performance/EndWith`
correct code like the following:

    path =~ %r{/\z}

To:

    path.end_with?('/')
  • Loading branch information
eugeneius authored and bbatsov committed Oct 28, 2019
1 parent bb55659 commit 18ff52e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
* [#7449](https://github.com/rubocop-hq/rubocop/pull/7449): Make `Style/IfUnlessModifier` respect `rubocop:disable` comments for `Metrics/LineLength`. ([@jonas054][])
* [#7442](https://github.com/rubocop-hq/rubocop/issues/7442): Fix an incorrect autocorrect for `Style/SafeNavigation` when an object check followed by a method call with a comment at EOL. ([@koic][])
* [#7434](https://github.com/rubocop-hq/rubocop/issues/7434): Fix an incorrect autocorrect for `Style/MultilineWhenThen` when the body of `when` branch starts with `then`. ([@koic][])
* [#7464](https://github.com/rubocop-hq/rubocop/pull/7464): Let `Performance/StartWith` and `Performance/EndWith` correct regexes that contain forward slashes. ([@eugeneius][])

### Changes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/util.rb
Expand Up @@ -9,7 +9,7 @@ module Util
# Match literal regex characters, not including anchors, character
# classes, alternatives, groups, repetitions, references, etc
LITERAL_REGEX =
/[\w\s\-,"'!#%&<>=;:`~]|\\[^AbBdDgGhHkpPRwWXsSzZ0-9]/.freeze
%r{[\w\s\-,"'!#%&<>=;:`~/]|\\[^AbBdDgGhHkpPRwWXsSzZ0-9]}.freeze

module_function

Expand Down

0 comments on commit 18ff52e

Please sign in to comment.