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",