summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2019-04-03 11:50:50 +0200
committerAustin Ziegler <austin@zieglers.ca>2019-04-03 17:06:21 -0400
commit1c8e13c7cd6b187c564afe8a05cadf51d8880fe1 (patch)
tree59c4c9fa98121b29aea8c8f81fbeb1a350edf39a
parenta698e17ec8998891bc6b50304ac4c3a129dcc52f (diff)
downloadmime-types-1c8e13c7cd6b187c564afe8a05cadf51d8880fe1.tar.gz
Intern content type strings
-rw-r--r--lib/mime/type.rb23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/mime/type.rb b/lib/mime/type.rb
index 5a05a91..552a888 100644
--- a/lib/mime/type.rb
+++ b/lib/mime/type.rb
@@ -537,11 +537,28 @@ class MIME::Type
match = MEDIA_TYPE_RE.match(type_string)
fail InvalidContentType, type_string if match.nil?
- @content_type = type_string
+ @content_type = intern_string(type_string)
@raw_media_type, @raw_sub_type = match.captures
- @simplified = MIME::Type.simplified(match)
- @i18n_key = MIME::Type.i18n_key(match)
+ @simplified = intern_string(MIME::Type.simplified(match))
+ @i18n_key = intern_string(MIME::Type.i18n_key(match))
@media_type, @sub_type = MEDIA_TYPE_RE.match(@simplified).captures
+
+ @raw_media_type = intern_string(@raw_media_type)
+ @raw_sub_type = intern_string(@raw_sub_type)
+ @media_type = intern_string(@media_type)
+ @sub_type = intern_string(@sub_type)
+ end
+
+ if String.method_defined?(:-@)
+ def intern_string(string)
+ -string
+ end
+ else
+ # MRI 2.2 and older don't have a method for string interning,
+ # so we simply freeze them for keeping a similar interface
+ def intern_string(string)
+ string.freeze
+ end
end
def xref_map(values, helper)