Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix:$http:Silently fail when isJsonLike wrongly detects JSON #12012

Closed

Conversation

fungiboletus
Copy link

isJsonLike can have false positives. Instead of crashing, the defaultHttpHandler should return the string.

It may be a problem for developers trying to load a broken JSON document without using the correct Content-Type. A log message could be added to the try-catch.

isJsonLike can have false positives.  Instead of crashing, the defaultHttpHandler should return the string.
@gkalpak
Copy link
Member

gkalpak commented Jun 3, 2015

@yellowiscool, thx for the PR. We should have a test verifying the new behaviour (i.e. a test that would fail prior to this change and passes with the change).

@petebacondarwin
Copy link
Contributor

Is this PR still relevant to 1.5 and 1.6?

@petebacondarwin
Copy link
Contributor

Looks like it was not changed yet. Adding to 1.6.x

@petebacondarwin petebacondarwin modified the milestones: 1.6.x (post 1.6.0), 1.4.x Sep 12, 2016
@Narretz
Copy link
Contributor

Narretz commented Apr 21, 2017

We made a different change to this behavior - http will now throw a specfic error when the data cannot be parsed as json.
It's not ideal that $http tries to parse everything as JSON based on isJSONLike, but changing this now would be a significant breaking change (we don't know how many people send JSON without proper headers). If you expect pure text or broken JSON, then changing the default transforms is the better option, see #15897

@Narretz Narretz closed this Apr 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants