From 6f2ee73073b55ef72dbfeeb94211db054bbea1c0 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Sun, 18 Aug 2019 18:03:41 +0800 Subject: [PATCH] feat: move encodeURIComponent to routes --- lib/routes/gov/zhengce/govall.js | 2 +- lib/utils/got.js | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/lib/routes/gov/zhengce/govall.js b/lib/routes/gov/zhengce/govall.js index bfdc229a2..3d717a175 100644 --- a/lib/routes/gov/zhengce/govall.js +++ b/lib/routes/gov/zhengce/govall.js @@ -12,7 +12,7 @@ module.exports = async (ctx) => { }); const query = `${params.toString()}&${advance}`; const res = await got.get(link, { - query: query, + query: query.replace(/([\u4e00-\u9fa5])/g, (str) => encodeURIComponent(str)), }); const $list = cheerio.load(res.data); diff --git a/lib/utils/got.js b/lib/utils/got.js index 162eb5529..0b0449cdf 100644 --- a/lib/utils/got.js +++ b/lib/utils/got.js @@ -38,15 +38,6 @@ const custom = got.extend({ options.query = options.query || queryString.stringify(options.params); } if (options.query) { - if (typeof options.query === 'string') { - options.query = options.query.replace(/([\u4e00-\u9fa5])/g, (str) => encodeURIComponent(str)); - } else if (typeof options.query === 'object') { - for (const key in options.query) { - if (typeof options.query[key] === 'string') { - options.query[key] = options.query[key].replace(/([\u4e00-\u9fa5])/g, (str) => encodeURIComponent(str)); - } - } - } options.searchParams = options.query; // for Got v11 after } },