Skip to content

Commit

Permalink
Fix an error for Naming/InclusiveLanguage string with invalid byte …
Browse files Browse the repository at this point in the history
…sequence in UTF-8
  • Loading branch information
ydah committed May 7, 2022
1 parent d392481 commit 5ff5b06
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
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

0 comments on commit 5ff5b06

Please sign in to comment.