Skip to content

Commit

Permalink
Refactor ascii? method
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkn committed May 27, 2021
1 parent 0de33cd commit 13e0447
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/iruby/display.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "set"

module IRuby
module Display
class << self
Expand Down Expand Up @@ -50,14 +52,15 @@ def protect(mime, data)
ascii?(mime) ? data.to_s : [data.to_s].pack('m0')
end

# Each of the following mime types must be a text type,
# but mime-types library tells us it is a non-text type.
FORCE_ASCII_TYPES = Set[
"application/javascript",
"image/svg+xml"
].freeze

def ascii?(mime)
case mime
when "application/javascript"
# Special case for application/javascript.
# This needs because mime-types tells us application/javascript a non-text type.
true
when "image/svg+xml"
# mime-types tells us image/svg+xml a non-text type.
if FORCE_ASCII_TYPES.include?(mime)
true
else
MIME::Type.new(mime).ascii?
Expand Down

0 comments on commit 13e0447

Please sign in to comment.