New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix an error when using regexp with non-encoding option #10432
Merged
bbatsov
merged 1 commit into
rubocop:master
from
koic:fix_an_error_when_using_regexp_with_noencoding_option
Feb 27, 2022
Merged
Fix an error when using regexp with non-encoding option #10432
bbatsov
merged 1 commit into
rubocop:master
from
koic:fix_an_error_when_using_regexp_with_noencoding_option
Feb 27, 2022
Conversation
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
koic
force-pushed
the
fix_an_error_when_using_regexp_with_noencoding_option
branch
from
February 21, 2022 15:31
1144278
to
3f97bc4
Compare
koic
changed the title
Fix an error when using regexp with non-encoding moption
Fix an error when using regexp with non-encoding option
Feb 21, 2022
koic
force-pushed
the
fix_an_error_when_using_regexp_with_noencoding_option
branch
3 times, most recently
from
February 21, 2022 15:38
d3082f2
to
db0ccab
Compare
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.
koic
force-pushed
the
fix_an_error_when_using_regexp_with_noencoding_option
branch
from
February 22, 2022 03:00
db0ccab
to
eaf40f8
Compare
koic
commented
Feb 22, 2022
|
||
# FIXME: Remove `broken_on: jruby` when JRuby incompatible is resolved: | ||
# https://github.com/jruby/jruby/issues/7113 | ||
context 'when processing a regex with regopt', broken_on: :jruby do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new test will be skipped due to JRuby incompatibility.
jruby/jruby#7113
Thanks! |
koic
deleted the
fix_an_error_when_using_regexp_with_noencoding_option
branch
February 27, 2022 06:29
8 tasks
koic
added a commit
to koic/rubocop
that referenced
this pull request
Feb 8, 2023
This PR reverts a pending test of rubocop#10432 because jruby/jruby#7113 has been resolved in JRuby 9.3.9.0. ## JRuby 9.3.3.0 `RegexpError` error will occur: ```console % rbenv local jruby-9.3.3.0 % ruby -e "Regexp.new('\x82', Regexp::NOENCODING)" RegexpError: invalid multibyte escape: /\x82/ initialize at org/jruby/RubyRegexp.java:956 new at org/jruby/RubyClass.java:893 <main> at -e:1 ``` ## JRuby 9.3.9.0 and JRuby 9.4.1.0 No errors: ```console % rbenv local jruby-9.3.9.0 % ruby -e "Regexp.new('\x82', Regexp::NOENCODING)" % rbenv local jruby-9.4.1.0 % ruby -e "Regexp.new('\x82', Regexp::NOENCODING)" ```
bbatsov
pushed a commit
that referenced
this pull request
Feb 8, 2023
This PR reverts a pending test of #10432 because jruby/jruby#7113 has been resolved in JRuby 9.3.9.0. ## JRuby 9.3.3.0 `RegexpError` error will occur: ```console % rbenv local jruby-9.3.3.0 % ruby -e "Regexp.new('\x82', Regexp::NOENCODING)" RegexpError: invalid multibyte escape: /\x82/ initialize at org/jruby/RubyRegexp.java:956 new at org/jruby/RubyClass.java:893 <main> at -e:1 ``` ## JRuby 9.3.9.0 and JRuby 9.4.1.0 No errors: ```console % rbenv local jruby-9.3.9.0 % ruby -e "Regexp.new('\x82', Regexp::NOENCODING)" % rbenv local jruby-9.4.1.0 % ruby -e "Regexp.new('\x82', Regexp::NOENCODING)" ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the following error when using regexp with non-encoding option.
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 callRegexpNode#to_regexp
defined in the RuboCop AST.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.