From 818e0cd0773433a8ba2410a2bf673ef9898ff607 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Sat, 15 Sep 2018 06:55:59 +0100 Subject: [PATCH] =?UTF-8?q?=E6=8B=AF=E6=95=91=E7=BF=BB=E8=BD=A6=E7=9A=84?= =?UTF-8?q?=20API=20(#698)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_router.js | 2 +- middleware/utf8.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api_router.js b/api_router.js index 004dca765..2b4cd8d8f 100644 --- a/api_router.js +++ b/api_router.js @@ -12,7 +12,7 @@ router.get('/routes/:name?', (ctx) => { const path = i.path; const top = path.split('/')[1]; - if (ctx.params.name === undefined || top === ctx.params.name) { + if (!ctx.params.name || top === ctx.params.name) { if (result[top]) { result[top].routes.push(path); } else { diff --git a/middleware/utf8.js b/middleware/utf8.js index 4c90349d0..b7ee6291f 100644 --- a/middleware/utf8.js +++ b/middleware/utf8.js @@ -2,5 +2,5 @@ // https://stackoverflow.com/questions/1497885/remove-control-characters-from-php-string/1497928#1497928 module.exports = async (ctx, next) => { await next(); - ctx.body = ctx.body ? ctx.body.replace(/[\x00-\x1F\x7F]/g, '') : ctx.body; + ctx.body = typeof ctx.body !== 'object' ? ctx.body.replace(/[\x00-\x1F\x7F]/g, '') : ctx.body; };