File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change 1+ require "set"
2+
13module 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?
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments