File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -21,14 +21,16 @@ class ContentType
2121 # Parse the given header value.
2222 #
2323 # @param string [String] Content-Type header value in RFC 2045 format
24+ # @param default_charset [String] Optional. The charset to use if none is
25+ # specified. Defaults to `us-ascii`.
2426 #
25- def initialize string
27+ def initialize string , default_charset : nil
2628 @string = string
2729 @media_type = "text"
2830 @subtype_base = @subtype = "plain"
2931 @subtype_format = nil
3032 @params = [ ]
31- @charset = "us-ascii"
33+ @charset = default_charset || "us-ascii"
3234 @error_message = nil
3335 parse consume_comments string . strip
3436 @canonical_string = "#{ @media_type } /#{ @subtype } " +
Original file line number Diff line number Diff line change 2929 assert Ractor . shareable? content_type if defined? Ractor
3030 end
3131
32+ it "defaults to us-ascii charset" do
33+ content_type = CloudEvents ::ContentType . new "application/json"
34+ assert_equal "us-ascii" , content_type . charset
35+ assert Ractor . shareable? content_type if defined? Ractor
36+ end
37+
38+ it "defaults to a given charset" do
39+ content_type = CloudEvents ::ContentType . new "application/json" , default_charset : "utf-8"
40+ assert_equal "utf-8" , content_type . charset
41+ assert Ractor . shareable? content_type if defined? Ractor
42+ end
43+
3244 it "recognizes charseet param" do
3345 content_type = CloudEvents ::ContentType . new "application/json; charset=utf-8"
3446 assert_equal [ [ "charset" , "utf-8" ] ] , content_type . params
You can’t perform that action at this time.
0 commit comments