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 for Naming/InclusiveLanguage string with invalid byte sequence in UTF-8 #10610

Merged
merged 1 commit into from May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_an_error_inclusive_language.md
@@ -0,0 +1 @@
* [#10610](https://github.com/rubocop/rubocop/pull/10610): Fix an error for `Naming/InclusiveLanguage` string with invalid byte sequence in UTF-8. ([@ydah][])
5 changes: 3 additions & 2 deletions lib/rubocop/cop/naming/inclusive_language.rb
Expand Up @@ -214,13 +214,14 @@ def scan_for_words(input)
end

def mask_input(str)
return str if @allowed_regex.nil?

safe_str = if str.valid_encoding?
str
else
str.encode('UTF-8', invalid: :replace, undef: :replace)
end

return safe_str if @allowed_regex.nil?

safe_str.gsub(@allowed_regex) { |match| '*' * match.size }
end

Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/naming/inclusive_language_spec.rb
Expand Up @@ -315,6 +315,12 @@ class Nodewhitelist
RUBY
end

it 'does not register offenses and not raise `ArgumentError` for invalid byte sequence in UTF-8' do
expect_no_offenses(<<-RUBY)
%W("a\\255\\255")
RUBY
end

context 'when CheckStrings config is false' do
let(:check_strings) { false }

Expand Down