提交 9ddb607e 编写于 作者: M mzabriskie

Using JSON.parse unconditionally when transforming response string

closes #55
上级 5ab9c2f0
......@@ -2,8 +2,6 @@
var utils = require('./utils');
var JSON_START = /^\s*(\[|\{[^\{])/;
var JSON_END = /[\}\]]\s*$/;
var PROTECTION_PREFIX = /^\)\]\}',?\n/;
var DEFAULT_CONTENT_TYPE = {
'Content-Type': 'application/x-www-form-urlencoded'
......@@ -30,9 +28,9 @@ module.exports = {
transformResponse: [function (data) {
if (typeof data === 'string') {
data = data.replace(PROTECTION_PREFIX, '');
if (JSON_START.test(data) && JSON_END.test(data)) {
try {
data = JSON.parse(data);
}
} catch (e) {}
}
return data;
}],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册