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

Fix an error when using regexp with non-encoding option #10432

Commits on Feb 22, 2022

  1. 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.
    koic committed Feb 22, 2022
    Copy the full SHA
    eaf40f8 View commit details
    Browse the repository at this point in the history