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

Infinite loop in Style/Encoding with uppercase token #12738

Closed
tbates-redarc opened this issue Mar 4, 2024 · 0 comments
Closed

Infinite loop in Style/Encoding with uppercase token #12738

tbates-redarc opened this issue Mar 4, 2024 · 0 comments
Labels

Comments

@tbates-redarc
Copy link

Running RuboCop autocorrect on a file containing a line:

# Encoding: UTF-8

causes an infinite loop. I think this is because EditorComment#without only matches on lowercase tokens.


Expected behavior

Rubocop removes the offending line.

Actual behavior

>rubocop --autocorrect
Inspecting 36 files
C

Offenses:

test.rb:1:1: C: [Corrected] Style/Encoding: Unnecessary utf-8 encoding comment.
# Encoding: UTF-8
^^^^^^^^^^^^^^^^^

0 files inspected, 1 offense detected, 1 offense corrected
Infinite loop detected in test.rb and caused by Style/Encoding
C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rubocop-1.61.0/lib/rubocop/runner.rb:332:in `check_for_infinite_loop'

Steps to reproduce the problem

  1. Create an file with an Encoding: UTF-8 comment (Encoding must not be all in lowercase).
  2. Run rubocop --autocorrect.

RuboCop version

1.61.0 (using Parser 3.3.0.5, rubocop-ast 1.31.1, running on ruby 3.1.3) [x64-mingw-ucrt]
@koic koic added the bug label Mar 4, 2024
koic added a commit to koic/rubocop that referenced this issue Mar 4, 2024
Fixees rubocop#12738.

This PR fixes an error for `Style/Encoding`
when magic encoding with mixed case present.
@bbatsov bbatsov closed this as completed in 6674cc8 Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants