From c522127473b6446fd276577efd5b884799311f47 Mon Sep 17 00:00:00 2001 From: Cr Date: Thu, 2 Jul 2020 11:28:22 +0800 Subject: [PATCH] fix: strip Bom before parse to json --- lib/adapters/http.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/adapters/http.js b/lib/adapters/http.js index 11cf22219b..7f42222092 100755 --- a/lib/adapters/http.js +++ b/lib/adapters/http.js @@ -235,14 +235,13 @@ module.exports = function httpAdapter(config) { var responseData = Buffer.concat(responseBuffer); if (config.responseType !== 'arraybuffer') { responseData = responseData.toString(config.responseEncoding); + if (!config.responseEncoding || config.responseEncoding === 'utf8') { + responseData = utils.stripBOM(responseData); + } // only response type 'json' return JSON response, 'text' and '' return string response if (config.responseType === 'json') { responseData = utils.tryParseJSON(responseData); } - - if (!config.responseEncoding || config.responseEncoding === 'utf8') { - responseData = utils.stripBOM(responseData); - } } response.data = responseData;