From 81ddb02afcdc31f9073792a224e6b1bc32add74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Wed, 23 Sep 2020 17:43:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A0=E6=95=88url?= =?UTF-8?q?=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 8 ++++++-- package.json | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 8ca30e2..ecf2ea7 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,8 @@ import URL from 'url' import QS from 'querystring' const tmpdir = process.cwd() + '/.tmp/' +const encode = encodeURIComponent +const decode = decodeURIComponent function hideProperty(host, name, value) { Object.defineProperty(host, name, { @@ -56,13 +58,15 @@ export default class Request { let pathArr = [] let tmpArr = [] + _url = decode(_url) + // URL上不允许有非法字符 if (/[^\w\-\/\.]/.test(_url)) { this.origin.res.rendered = true this.origin.res.writeHead(400, { - 'X-debug': 'url[' + _url + '] contains illegal characters' + 'X-debug': `url [/${encode(_url)}] contains invalid characters` }) - return this.origin.res.end('') + return this.origin.res.end(`Invalid characters: /${_url}`) } // 修正url中可能出现的"多斜杠" diff --git a/package.json b/package.json index 170d580..1aa13c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gm5/request", - "version": "1.2.0", + "version": "1.2.1", "description": "对Http的request进一步封装, 提供常用的API", "main": "index.js", "author": "yutent",