Skip to content
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

Regexp in UTF-8 causes issues in Lint/OutOfRangeRegexRef #10552

Closed
m11o opened this issue Apr 20, 2022 · 3 comments · Fixed by rubocop/rubocop-ast#230
Closed

Regexp in UTF-8 causes issues in Lint/OutOfRangeRegexRef #10552

m11o opened this issue Apr 20, 2022 · 3 comments · Fixed by rubocop/rubocop-ast#230
Labels

Comments

@m11o
Copy link

m11o commented Apr 20, 2022

Expected behavior

Lint/OutOfRangeRegexRef would not alert when using utf-8 encoding.

Actual behavior

Rubocop alerted when using encoding utf-8 ( /u ). But, Rubocop didn't alert when not using it.

Steps to reproduce the problem

Given the code:

/^(\d+)-(\S+)$/u =~ value
if $1 != target
  # do something
end

=> NG

W: Lint/OutOfRangeRegexpRef: $1 is out of range (no regexp capture groups detected).
if $1 != target
   ^^
/^(\d+)-(\S+)$/ =~ value
if $1 != target
  # do something
end

=> OK

RuboCop version

$ bundle exec rubocop -V
1.25.1 (using Parser 3.1.1.0, rubocop-ast 1.16.0, running on ruby 2.7.5 x86_64-linux)
  - rubocop-rails 2.13.2

Please tell me why they occur. Thank you!

@koic koic added the bug label Apr 20, 2022
koic added a commit to koic/rubocop-ast that referenced this issue Apr 20, 2022
Resolves rubocop/rubocop#10552.

This PR makes `RegexpNode` aware of fixed-encoding regopt.
@m11o
Copy link
Author

m11o commented Apr 21, 2022

Appendix

/^(\d+)-(\S+)$/u =~ value
if Regexp.last_match(1) != target
  # do something
end

=> OK

koic added a commit to koic/rubocop-ast that referenced this issue Aug 5, 2022
Resolves rubocop/rubocop#10552.

This PR makes `RegexpNode` aware of fixed-encoding regopt.
@marcandre
Copy link
Contributor

marcandre commented Aug 7, 2022

Looks good :-)

@koic
Copy link
Member

koic commented Aug 7, 2022

@marcandre I've opened rubocop/rubocop-ast#230 to resolve this issue. Can you review it?

marcandre pushed a commit to rubocop/rubocop-ast that referenced this issue Aug 7, 2022
Resolves rubocop/rubocop#10552.

This PR makes `RegexpNode` aware of fixed-encoding regopt.
koic added a commit that referenced this issue Aug 8, 2022
Follow up rubocop/rubocop-ast#230 and fixes #10552.

This commit fixes a false positive for `Lint/OutOfRangeRegexpRef` when using
fixed-encoding regopt.
WJWH pushed a commit to WJWH/rubocop that referenced this issue Aug 8, 2022
Follow up rubocop/rubocop-ast#230 and fixes rubocop#10552.

This commit fixes a false positive for `Lint/OutOfRangeRegexpRef` when using
fixed-encoding regopt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants