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

defaultHttpResponseTransform tries to parse as Json "text/plain" that isn't Json #16027

Closed
@r20

Description

@r20

I'm submitting a ...

  • [x ] bug report
  • feature request
  • other (Please do not submit support requests here (see above))

Current behavior:

function defaultHttpResponseTransform(data, headers) {
  if (isString(data)) {
    // Strip json vulnerability protection prefix and trim whitespace
    var tempData = data.replace(JSON_PROTECTION_PREFIX, '').trim();

    if (tempData) {
      var contentType = headers('Content-Type');
      if ((contentType && (contentType.indexOf(APPLICATION_JSON) === 0)) || isJsonLike(tempData)) {
        try {
          data = fromJson(tempData);
        } catch (e) {
          throw $httpMinErr('baddata', 'Data must be a valid JSON object. Received: "{0}". ' +
          'Parse error: "{1}"', data, e);
        }
      }
    }
  }

  return data;
}

In defaultHttpResponseTransform() if the response data passes the isJsonLike() function, the function tries to transform the data using fromJson(). This may fail if the data isn't actually Json. If a server sends contentType "text/plain" with data "{a}" or "[a]" for example, these will result in angular throwing an error.

Expected / new behavior:

If the contentType is "text/plain", the defaultHttpResponseTransform should return the data without trying to change it.

Angular version: 1.6.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions