Skip to content

Commit adaa247

Browse files
authored
Merge pull request #301 from kojix2/mime-type-svg
Make image/svg+xml a text type
2 parents ea294f4 + 89f0678 commit adaa247

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/iruby/display.rb

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "set"
2+
13
module IRuby
24
module Display
35
class << self
@@ -50,11 +52,15 @@ def protect(mime, data)
5052
ascii?(mime) ? data.to_s : [data.to_s].pack('m0')
5153
end
5254

55+
# Each of the following mime types must be a text type,
56+
# but mime-types library tells us it is a non-text type.
57+
FORCE_TEXT_TYPES = Set[
58+
"application/javascript",
59+
"image/svg+xml"
60+
].freeze
61+
5362
def ascii?(mime)
54-
case mime
55-
when "application/javascript"
56-
# Special case for application/javascript.
57-
# This needs because mime-types tells us application/javascript a non-text type.
63+
if FORCE_TEXT_TYPES.include?(mime)
5864
true
5965
else
6066
MIME::Type.new(mime).ascii?

test/iruby/mime_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ class IRubyTest::MimeTest < IRubyTest::TestBase
1919
assert_equal(data,
2020
res["application/javascript"])
2121
end
22+
23+
test("image/svg+xml") do
24+
data = '<svg height="30" width="100"><text x="0" y="15" fill="red">SVG</text></svg>'
25+
res = IRuby::Display.display(data, mime: "image/svg+xml")
26+
assert_equal(data,
27+
res["image/svg+xml"])
28+
end
2229
end
2330
end
2431
end

0 commit comments

Comments
 (0)