• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

koajs/qs: qs for koa, and use querystring more safely.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

koajs/qs

开源软件地址:

https://github.com/koajs/qs

开源编程语言:

JavaScript 100.0%

开源软件介绍:

Koa Querystring

NPM version build status Test coverage David deps node version npm download

By default, Koa uses the native querystring module which does not provide nesting support. This patches a koa app with nesting support via the qs support, which is also used by Connect and Express.

Simply wrap a koa app with this module:

// Koa 1.x.x
const koa = require('koa')
const app = koa()
require('koa-qs')(app)
// Koa 2.x.x
const Koa = require('koa')
const app = new Koa()
require('koa-qs')(app)

Optional parse mode

There're three parse mode.

extended mode

The default mode, use [qs] module.

require('koa-qs')(app, 'extended')

simple mode

Use querystring module, same as koa does by default. If you want to use this mode, don't use this module.

strict mode

This mode make this.query.foo return strict array.

require('koa-qs')(app, 'strict')

What's different

A normal request GET /foo?p=a&q=foo&q=bar.

  • before patch
console.log('%j', this.query);
{
  "p": "a",
  "q": ["foo", "bar"]
}
  • after patch
console.log('%j', this.query);
{
  "p": ["a"],
  "q": ["foo", "bar"]
}

first mode

This mode make this.query.foo return strict string. Disable multi values.

If querystring contains multi same name params, return the first item.

require('koa-qs')(app, 'first')

In 95% use cases, application only want string query params.

This patch can avoid some stupid TypeError and some security issues like MongoDB inject when the developers forget handling query params type check.

What's different

A normal request GET /foo?p=a,b&p=b,c.

  • before patch
console.log('%j', this.query.p);
["a,b", "b,c"]
  • after patch
console.log('%j', this.query.p);
"a,b"

License

MIT




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap