Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions msrest/pipeline/universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import xml.etree.ElementTree as ET
import platform
import codecs
import re

from typing import Mapping, Any, Optional, AnyStr, Union, IO, cast, TYPE_CHECKING # pylint: disable=unused-import

Expand Down Expand Up @@ -129,10 +130,9 @@ def on_response(self, request, response, **kwargs):

class RawDeserializer(SansIOHTTPPolicy):

JSON_MIMETYPES = [
'application/json',
'text/json' # Because we're open minded people...
]
# Accept "text" because we're open minded people...
JSON_REGEXP = re.compile(r'^(application|text)/([a-z+.]+\+)?json$')

# Name used in context
CONTEXT_NAME = "deserialized_data"

Expand Down Expand Up @@ -165,7 +165,7 @@ def deserialize_from_text(cls, data, content_type=None):
if content_type is None:
return data

if content_type in cls.JSON_MIMETYPES:
if cls.JSON_REGEXP.match(content_type):
try:
return json.loads(data_as_str)
except ValueError as err:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_universal_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ def body(self):
result = response.context["deserialized_data"]
assert result["success"] is True

# Simple JSON with complex content_type
response = build_response(b'{"success": true}', content_type="application/vnd.microsoft.appconfig.kv+json")
raw_deserializer.on_response(None, response, stream=False)
result = response.context["deserialized_data"]
assert result["success"] is True

# JSON with UTF-8 BOM
response = build_response(b'\xef\xbb\xbf{"success": true}', content_type="application/json; charset=utf-8")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't adding a BOM in violation of https://tools.ietf.org/html/rfc7158#section-8.1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raw_deserializer.on_response(None, response, stream=False)
Expand Down