yutent 2023-02-09 19:00:53 +08:00
parent efe2c384d8
commit 148684bf35
2 changed files with 11 additions and 6 deletions

View File

@ -57,10 +57,8 @@ export default class Request {
let pathArr = []
let tmpArr = []
_url = decode(_url)
// URL上不允许有非法字符
if (/[^\w-/.@~!$&:+'=]/.test(_url)) {
if (/[^\w-/.@~!$&:+'=]/.test(decode(_url))) {
this.origin.res.rendered = true
this.origin.res.writeHead(400, {
'X-debug': `url [/${encode(_url)}] contains invalid characters`
@ -135,7 +133,11 @@ export default class Request {
this.__GET__ = para
}
return key ? (this.__GET__.hasOwnProperty(key) ? this.__GET__[key] : null) : this.__GET__
return key
? this.__GET__.hasOwnProperty(key)
? this.__GET__[key]
: null
: this.__GET__
}
/**
@ -169,7 +171,10 @@ export default class Request {
return
}
if (~contentType.indexOf('urlencoded')) {
if (name.slice(0, 2) === '{"' && (name.slice(-2) === '"}' || value.slice(-2) === '"}')) {
if (
name.slice(0, 2) === '{"' &&
(name.slice(-2) === '"}' || value.slice(-2) === '"}')
) {
name = name.replace(/\s/g, '+')
if (value.slice(0, 1) === '=') value = '=' + value

View File

@ -1,6 +1,6 @@
{
"name": "@gm5/request",
"version": "1.2.7",
"version": "1.2.8",
"description": "对Http的request进一步封装, 提供常用的API",
"main": "index.js",
"author": "yutent",