Skip to content

Commit

Permalink
Fix Lint/UnescapedBracketInRegexp cop failure with invalid multibyt…
Browse files Browse the repository at this point in the history
…e escape

This is a followup to rubocop#13522.
The added regex raises a `ScannerError`, which doesn't inherit from `ParserError`.
  • Loading branch information
Earlopain authored and bbatsov committed Dec 12, 2024
1 parent b00b5f1 commit 4618790
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/fix_error_unescaped_bracket_scanner_error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#13573](https://github.com/rubocop/rubocop/pull/13573): Fix `Lint/UnescapedBracketInRegexp` cop failure with invalid multibyte escape. ([@earlopain][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/unescaped_bracket_in_regexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def on_send(node)
Regexp::Parser.parse(text.value)&.each_expression do |expr|
detect_offenses(text, expr)
end
rescue Regexp::Parser::ParserError
rescue Regexp::Parser::Error
# Upon encountering an invalid regular expression,
# we aim to proceed and identify any remaining potential offenses.
end
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/lint/unescaped_bracket_in_regexp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
end

context 'invalid regular expressions' do
%w[+ * {42}].each do |invalid_regexp|
%w[+ * {42} \xff].each do |invalid_regexp|
it "does not register an offense for single invalid `/#{invalid_regexp}/` regexp`" do
expect_no_offenses(<<~RUBY)
Regexp.#{method}("#{invalid_regexp}")
Expand Down

0 comments on commit 4618790

Please sign in to comment.