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

invalid byte sequence in UTF-8 error while linting regexp with Lint/MixedCaseRange cop #12703

Closed
larouxn opened this issue Feb 20, 2024 · 1 comment · Fixed by #12751
Closed
Labels

Comments

@larouxn
Copy link

larouxn commented Feb 20, 2024

Running linting with the Lint/MixedCaseRange cop enabled leads to an error when linting the following regular expression line. Surely a complex line but not a range in the first place but rather a regular expression. Plus, the line has been working fine in production for months so while I'm not 100% sure it's a RuboCop issue, I'm tempted to say it is.

term.gsub(%r{[\s\.\-\–\&\,\:\;\!\?/\'\"\`\%\+\(\)\[\]]}, "").downcase

Expected behavior

No error nor linting issue is reported when running over the above line with the aforementioned cop.

Actual behavior

Inspecting 1 file
An error occurred while Lint/MixedCaseRange cop was inspecting some_file.rb:104:16.
To see the complete backtrace run rubocop -d.
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Lint/MixedCaseRange cop was inspecting some_file.rb:104:16.
Errors are usually caused by RuboCop bugs.

Running with --debug flag, it appears the error is an invalid byte sequence. 🤔

An error occurred while Lint/MixedCaseRange cop was inspecting some_file.rb:104:16.
invalid byte sequence in UTF-8

Steps to reproduce the problem

  1. Add the gsub line above to a Ruby file.
  2. Run bundle exec rubocop --only Lint/MixedCaseRange --debug the_file.rb.

RuboCop version

❯ rubocop -V
1.60.2 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 3.3.0) [x86_64-linux]
  - rubocop-factory_bot 2.25.1
  - rubocop-minitest 0.34.5
  - rubocop-performance 1.20.2
  - rubocop-rails 2.23.1
  - rubocop-sorbet 0.7.7
@koic koic added the bug label Feb 21, 2024
Earlopain added a commit to Earlopain/rubocop that referenced this issue Mar 6, 2024
koic added a commit that referenced this issue Mar 7, 2024
[Fix #12703] Fix an error for `Lint/MixedCaseRange` with invalid byte sequence in UTF-8
@larouxn
Copy link
Author

larouxn commented Mar 7, 2024

Thanks a bunch for the fix! I can confirm (on RuboCop main) that the regex line above lints fine now. 😌

Inspecting 1 file
.

1 file inspected, no offenses detected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants