mirror of
https://github.com/sprockets/sprockets.mixins.mediatype.git
synced 2024-12-29 11:17:10 +00:00
Strip charset parameter from text content types.
This commit is contained in:
parent
995c715405
commit
ed357d878f
2 changed files with 16 additions and 2 deletions
|
@ -148,9 +148,15 @@ def add_text_content_type(application, content_type, default_encoding,
|
|||
:param loads: function that loads a dictionary from a string.
|
||||
``loads(str, encoding:str) -> dict``
|
||||
|
||||
Note that the ``charset`` parameter is stripped from `content_type`
|
||||
if it is present.
|
||||
|
||||
"""
|
||||
add_transcoder(application, content_type,
|
||||
handlers.TextContentHandler(content_type, dumps, loads,
|
||||
parsed = headers.parse_content_type(content_type)
|
||||
parsed.parameters.pop('charset', None)
|
||||
normalized = str(parsed)
|
||||
add_transcoder(application, normalized,
|
||||
handlers.TextContentHandler(normalized, dumps, loads,
|
||||
default_encoding))
|
||||
|
||||
|
||||
|
|
8
tests.py
8
tests.py
|
@ -240,6 +240,14 @@ class ContentFunctionTests(unittest.TestCase):
|
|||
self.assertIs(transcoder._dumps, json.dumps)
|
||||
self.assertIs(transcoder._loads, json.loads)
|
||||
|
||||
def test_that_add_text_content_type_discards_charset_parameter(self):
|
||||
content.add_text_content_type(self.context,
|
||||
'application/json;charset=UTF-8', 'utf8',
|
||||
json.dumps, json.loads)
|
||||
settings = content.ContentSettings.from_application(self.context)
|
||||
transcoder = settings['application/json']
|
||||
self.assertIsInstance(transcoder, handlers.TextContentHandler)
|
||||
|
||||
|
||||
class MsgPackTranscoderTests(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Reference in a new issue