-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix($http): won't parse single space response #9907
Conversation
I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS. Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match. If you signed the CLA as a corporation, please let us know the company's name. Thanks a bunch! PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR. |
@@ -782,7 +782,7 @@ function $HttpProvider() { | |||
function transformResponse(response) { | |||
// make a copy since the response must be cacheable | |||
var resp = extend({}, response); | |||
if (!response.data) { | |||
if (!response.data || response.data === '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this doesn't actually make sense, since ''
is still falsy
795880a
to
246a667
Compare
Rails sends a single space response instead of empty headers, this change will not attempt to parse the response
246a667
to
382f1a1
Compare
@gampleman thnx for this PR but I don't think we can merge it as-is - see my comments in the code. |
So while it kind of make sense that we trim strings before running it through toJson people could easily work-arround it already by adding a custom transformer so I guess it is not critically urgent that we get this fix in. |
OK, so I've changed it to check right before attempting to parse the JSON that the response isn't just blank. Side note: For us it's a blocker on upgrading to Angular 1.3, since all our APIs have this behaviour. We don't want to change Rails and while adding a custom transformer everywhere is an option, it doesn't seem too attractive. |
LGTM, merging |
According to this question, Rails in order to patch a bug in Safari, returns a single space when calling
head :ok
, which is the standard for POST requests.Angular since 9ba24c54d checks if the body is empty before calling JSON parse, but this still breaks in this case, since the body isn't empty, but contains a single space.
We are hitting this issue when trying to upgrade from Angular 1.2.10. This PR should help in that case.