Skip to content

Commit

Permalink
Merge pull request #8315 from eugeneius/percent_literal_delimiters_scrub
Browse files Browse the repository at this point in the history
Handle invalid characters in Style/PercentLiteralDelimiters
  • Loading branch information
koic committed Jul 13, 2020
2 parents 0a62a31 + 528bf00 commit c7b494b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* [#8282](https://github.com/rubocop-hq/rubocop/issues/8282): Fix `Style/IfUnlessModifier` bad precedence detection. ([@tejasbubane][])
* [#8289](https://github.com/rubocop-hq/rubocop/issues/8289): Fix `Style/AccessorGrouping` to not register offense for accessor with comment. ([@tejasbubane][])
* [#8310](https://github.com/rubocop-hq/rubocop/pull/8310): Handle major version requirements in `Gemspec/RequiredRubyVersion`. ([@eugeneius][])
* [#8315](https://github.com/rubocop-hq/rubocop/pull/8315): Fix crash for `Style/PercentLiteralDelimiters` when the source contains invalid characters. ([@eugeneius][])

### Changes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/percent_literal_delimiters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def contains_delimiter?(node, delimiters)
delimiters_regexp = Regexp.union(delimiters)
node
.children.map { |n| string_source(n) }.compact
.any? { |s| delimiters_regexp.match?(s) }
.any? { |s| delimiters_regexp.match?(s.scrub) }
end

def string_source(node)
Expand Down
4 changes: 4 additions & 0 deletions spec/rubocop/cop/style/percent_literal_delimiters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
^^^^^^^^^^^^^^^ `%`-literals should be delimited by `[` and `]`.
RUBY
end

it 'does not crash when the source contains invalid characters' do
expect { inspect_source('%{\x80}') }.not_to raise_error
end
end

context '`%q` string' do
Expand Down

0 comments on commit c7b494b

Please sign in to comment.