Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix an error when using regexp with non-encoding option
This PR fixes the following error when using regexp with non-encoding option. ```console % cat /tmp/example.rb /\x82/n =~ 'a' % rubocop -d /tmp/example.rb (snip) For /tmp: An error occurred while VariableForce cop was inspecting /tmp/example.rb. invalid multibyte escape: /\x82/ /Users/koic/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/cop/variable_force.rb:193:in `initialize' /Users/koic/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/rubocop-1.25.1/lib/rubocop/cop/variable_force.rb:193:in `new' ``` This error is due to `VariableForce#regexp_captured_names` not processing the regexp option. This PR uses `RegexpNode#to_regexp` to prevent the regexp option from being cut. In addition, the test code replaces the Parser gem (plain) AST with `ProcessedSource#ast` so that it can call `RegexpNode#to_regexp` defined in the RuboCop AST.
- Loading branch information
Showing
3 changed files
with
18 additions
and
13 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
changelog/fix_an_error_when_using_regexp_with_noencoding_option.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#10432](https://github.com/rubocop/rubocop/pull/10432): Fix an error when using regexp with non-encoding option. ([@koic][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters