Skip to content

Commit

Permalink
Fix bug in counting slashes in a regexp.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas054 committed Jul 27, 2013
1 parent 9a58fbb commit ca0843a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [#374](https://github.com/bbatsov/rubocop/issues/374) - Fixed error at post condition loop (`begin-end-while`, `begin-end-until`) in `UnusedLocalVariable` and `ShadowingOuterLocalVariable`
* [#373](https://github.com/bbatsov/rubocop/issues/373) and [#376](https://github.com/bbatsov/rubocop/issues/376) - allow braces around multi-line blocks if `do`-`end` would change the meaning of the code
* `RedundantSelf` now allows `self.` followed by any ruby keyword
* [#391](https://github.com/bbatsov/rubocop/issues/391) - Fix bug in counting slashes in a regexp.

## 0.10.0 (17/07/2013)

Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/style/regexp_literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ module Style
# value of the configuration parameter MaxSlashes.
class RegexpLiteral < Cop
def on_regexp(node)
slashes = node.loc.expression.source[1...-1].scan(/\//).size
slashes = node.loc.expression.source.count('/')
max = RegexpLiteral.max_slashes
msg = if node.loc.begin.is?('/')
slashes -= 2 # subtract delimiters
error_message('') if slashes > max
else
error_message('only ') if slashes <= max
Expand Down
1 change: 1 addition & 0 deletions spec/rubocop/cops/style/regexp_literal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module Style
it 'accepts zero or one slash in regexp' do
inspect_source(rl, ['x =~ /\/home/',
'y =~ /\//',
'w =~ /\//m',
'z =~ /a/'])
expect(rl.offences).to be_empty
end
Expand Down

0 comments on commit ca0843a

Please sign in to comment.