Skip to content

Commit

Permalink
Avoid array creation when checking if source is UTF-8 (#1141)
Browse files Browse the repository at this point in the history
This commit replaces a check that involved the creation of an arrays of
strings with a direct comparison against those three strings.
  • Loading branch information
ashmaroli authored and pyrmont committed Jun 1, 2019
1 parent df23679 commit a3d4091
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rouge/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ def mimetypes(*mts)

# @private
def assert_utf8!(str)
return if %w(US-ASCII UTF-8 ASCII-8BIT).include? str.encoding.name
encoding = str.encoding.name
return if encoding == 'US-ASCII' || encoding == 'UTF-8' || encoding == 'ASCII-8BIT'

raise EncodingError.new(
"Bad encoding: #{str.encoding.names.join(',')}. " +
"Please convert your string to UTF-8."
Expand Down

0 comments on commit a3d4091

Please sign in to comment.