-
Notifications
You must be signed in to change notification settings - Fork 13
fix json emitter for empty response bodies #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
16da517
91dd39d
fe2c91f
81a9a8c
aef8eb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,19 +183,23 @@ def decode(self, data): | |
| def render(self, request): | ||
| cb = request.GET.get("callback", None) | ||
| assert cb is None, "JSONP Callbacks not suppoted" | ||
| seria = json.dumps( | ||
| self.decode(self.construct()), | ||
| cls=DjangoJSONEncoder, | ||
| ensure_ascii=False, | ||
| indent=4, | ||
| ) | ||
| seria = self.decode(self.construct()) | ||
| if isinstance(seria, list): | ||
| if len(seria) == 0 or (len(seria) == 1 and len(seria[0]) == 0): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume in some cases self.decode returns a tuple or something and that's the cause of the clause after the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The base case (len == 0) is a just in case. What we actually see with our current issue is |
||
| # the body is empty, no need to run json.dumps | ||
| return "" | ||
|
|
||
| # Callback | ||
| # TODO: do we care about JSONP? | ||
| # if cb and is_valid_jsonp_callback_value(cb): | ||
| # return '%s(%s)' % (cb, seria) | ||
|
|
||
| return seria | ||
| return json.dumps( | ||
| seria, | ||
| cls=DjangoJSONEncoder, | ||
| ensure_ascii=False, | ||
| indent=4, | ||
| ) | ||
|
|
||
|
|
||
| Emitter.register("json", JSONEmitter, "application/json; charset=utf-8") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,11 @@ def test_decode(self): | |
| resp = em.render(django.test.RequestFactory().get("/")) | ||
| self.assertEqual(json.loads(resp), ["foo", "bar"]) | ||
|
|
||
| def test_decode_empty_list(self): | ||
| em = emitters.JSONEmitter([""], lambda: None) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for completeness don't we want another test with a truly empty list? |
||
| resp = em.render(django.test.RequestFactory().get("/")) | ||
| self.assertEqual(resp, "") | ||
|
|
||
|
|
||
| class DjangoEmitterTestCase(unittest.TestCase): | ||
| def test_render_http_response_succes(self): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.