# qs <sup>[![Version Badge][2]][1]</sup>
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
A querystring parsing and stringifying library with some added security.
Lead Maintainer: [Jordan Harband](https://github.com/ljharb)
The **qs** module was originally created and maintained by [TJ Holowaychuk](https://github.com/visionmedia/node-querystring).
## Usage
```javascript
var qs = require('qs');
var assert = require('assert');
var obj = qs.parse('a=c');
assert.deepEqual(obj, { a: 'c' });
var str = qs.stringify(obj);
assert.equal(str, 'a=c');
```
### Parsing Objects
[](#preventEval)
```javascript
qs.parse(string, [options]);
```
**qs** allows you to create nested objects within your query strings, by surrounding the name of sub-keys with square brackets `[]`.
For example, the string `'foo[bar]=baz'` converts to:
```javascript
assert.deepEqual(qs.parse('foo[bar]=baz'), {
foo: {
bar: 'baz'
}
});
```
When using the `plainObjects` option the parsed value is returned as a null object, created via `Object.create(null)` and as such you should be aware that prototype methods will not exist on it and a user may set those names to whatever value they like:
```javascript
var nullObject = qs.parse('a[hasOwnProperty]=b', { plainObjects: true });
assert.deepEqual(nullObject, { a: { hasOwnProperty: 'b' } });
```
By default parameters that would overwrite properties on the object prototype are ignored, if you wish to keep the data from those fields either use `plainObjects` as mentioned above, or set `allowPrototypes` to `true` which will allow user input to overwrite those properties. *WARNING* It is generally a bad idea to enable this option as it can cause problems when attempting to use the properties that have been overwritten. Always be careful with this option.
```javascript
var protoObject = qs.parse('a[hasOwnProperty]=b', { allowPrototypes: true });
assert.deepEqual(protoObject, { a: { hasOwnProperty: 'b' } });
```
URI encoded strings work too:
```javascript
assert.deepEqual(qs.parse('a%5Bb%5D=c'), {
a: { b: 'c' }
});
```
You can also nest your objects, like `'foo[bar][baz]=foobarbaz'`:
```javascript
assert.deepEqual(qs.parse('foo[bar][baz]=foobarbaz'), {
foo: {
bar: {
baz: 'foobarbaz'
}
}
});
```
By default, when nesting objects **qs** will only parse up to 5 children deep. This means if you attempt to parse a string like
`'a[b][c][d][e][f][g][h][i]=j'` your resulting object will be:
```javascript
var expected = {
a: {
b: {
c: {
d: {
e: {
f: {
'[g][h][i]': 'j'
}
}
}
}
}
}
};
var string = 'a[b][c][d][e][f][g][h][i]=j';
assert.deepEqual(qs.parse(string), expected);
```
This depth can be overridden by passing a `depth` option to `qs.parse(string, [options])`:
```javascript
var deep = qs.parse('a[b][c][d][e][f][g][h][i]=j', { depth: 1 });
assert.deepEqual(deep, { a: { b: { '[c][d][e][f][g][h][i]': 'j' } } });
```
The depth limit helps mitigate abuse when **qs** is used to parse user input, and it is recommended to keep it a reasonably small number.
For similar reasons, by default **qs** will only parse up to 1000 parameters. This can be overridden by passing a `parameterLimit` option:
```javascript
var limited = qs.parse('a=b&c=d', { parameterLimit: 1 });
assert.deepEqual(limited, { a: 'b' });
```
To bypass the leading question mark, use `ignoreQueryPrefix`:
```javascript
var prefixed = qs.parse('?a=b&c=d', { ignoreQueryPrefix: true });
assert.deepEqual(prefixed, { a: 'b', c: 'd' });
```
An optional delimiter can also be passed:
```javascript
var delimited = qs.parse('a=b;c=d', { delimiter: ';' });
assert.deepEqual(delimited, { a: 'b', c: 'd' });
```
Delimiters can be a regular expression too:
```javascript
var regexed = qs.parse('a=b;c=d,e=f', { delimiter: /[;,]/ });
assert.deepEqual(regexed, { a: 'b', c: 'd', e: 'f' });
```
Option `allowDots` can be used to enable dot notation:
```javascript
var withDots = qs.parse('a.b=c', { allowDots: true });
assert.deepEqual(withDots, { a: { b: 'c' } });
```
If you have to deal with legacy browsers or services, there's
also support for decoding percent-encoded octets as iso-8859-1:
```javascript
var oldCharset = qs.parse('a=%A7', { charset: 'iso-8859-1' });
assert.deepEqual(oldCharset, { a: '§' });
```
Some services add an initial `utf8=✓` value to forms so that old
Internet Explorer versions are more likely to submit the form as
utf-8. Additionally, the server can check the value against wrong
encodings of the checkmark character and detect that a query string
or `application/x-www-form-urlencoded` body was *not* sent as
utf-8, eg. if the form had an `accept-charset` parameter or the
containing page had a different character set.
**qs** supports this mechanism via the `charsetSentinel` option.
If specified, the `utf8` parameter will be omitted from the
returned object. It will be used to switch to `iso-8859-1`/`utf-8`
mode depending on how the checkmark is encoded.
**Important**: When you specify both the `charset` option and the
`charsetSentinel` option, the `charset` will be overridden when
the request contains a `utf8` parameter from which the actual
charset can be deduced. In that sense the `charset` will behave
as the default charset rather than the authoritative charset.
```javascript
var detectedAsUtf8 = qs.parse('utf8=%E2%9C%93&a=%C3%B8', {
charset: 'iso-8859-1',
charsetSentinel: true
});
assert.deepEqual(detectedAsUtf8, { a: 'ø' });
// Browsers encode the checkmark as ✓ when submitting as iso-8859-1:
var detectedAsIso8859_1 = qs.parse('utf8=%26%2310003%3B&a=%F8', {
charset: 'utf-8',
charsetSentinel: true
});
assert.deepEqual(detectedAsIso8859_1, { a: 'ø' });
```
If you want to decode the `&#...;` syntax to the actual character,
you can specify the `interpretNumericEntities` option as well:
```javascript
var detectedAsIso8859_1 = qs.parse('a=%26%239786%3B', {
charset: 'iso-8859-1',
interpretNumericEntities: true
});
assert.deepEqual(detectedAsIso8859_1, { a: '☺' });
```
It also works when the charset has been detected in `charsetSentinel`
mode.
### Parsing Arrays
**qs** can also parse arrays using a similar `[]` notation:
```javascript
var withArray = qs.parse('a[]=b&a[]=c');
assert.deepEqual(withArray, { a: ['b', 'c'] });
```
You may specify an index as well:
```javascript
var withIndexes = qs.parse('a[1]=c&a[0]=b');
assert.deepEqual(withIndexes, { a: ['b', 'c'] });
```
Note that the only difference between an index in an array and a key in an object is that the value between the brackets must be a number
to create an array. When creating arrays with specific indices, **qs** will compact a sparse array to only the existing values preserving
their order:
```javascript
var noSparse = qs.parse('a[1]=b&a[15]=c');
assert.deepEqual(noSparse, { a: ['b', 'c'] });
```
You may also use `allowSparse` option to parse sparse arrays:
```javascript
var sparseArray = qs.parse('a[1]=2&a[3]=5', { allowSparse: true });
assert.deepEqual(sparseArray, { a: [, '2', , '5'] });
```
Note that an empty string is also a value, and will be preserved:
```javascript
var withEmptyString = qs.parse('a[]=&a[]=b');
assert.deepEqual(withEmptyString, { a: ['', 'b'] });
var withIndexedEmptyString = qs.parse('a[0]=b&a[1]=&a[2]=c');
assert.deepEqual(withIndexedEmptyString, { a: ['b', '', 'c'] });
```
**qs** will also limit specifying indices in an array to a maximum index of `20`. Any array members with an index of greater than `20` will
instead
没有合适的资源?快使用搜索试试~ 我知道了~
基于Springboot + Vue 开发的前后端分离博客(PC端自适应+移动端微信小程序+移动端App).zip
共1382个文件
js:659个
java:282个
vue:184个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 78 浏览量
2024-12-04
18:35:08
上传
评论
收藏 2.22MB ZIP 举报
温馨提示
【资源说明】 基于Springboot + Vue 开发的前后端分离博客(PC端自适应+移动端微信小程序+移动端App).zip 【备注】 1、该项目是个人高分项目源码,已获导师指导认可通过,答辩评审分达到95分 2、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 3、本项目适合计算机相关专业(人工智能、通信工程、自动化、电子信息、物联网等)的在校学生、老师或者企业员工下载使用,也可作为毕业设计、课程设计、作业、项目初期立项演示等,当然也适合小白学习进阶。 4、如果基础还行,可以在此代码基础上进行修改,以实现其他功能,也可直接用于毕设、课设、作业等。 欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
基于Springboot + Vue 开发的前后端分离博客(PC端自适应+移动端微信小程序+移动端App).zip (1382个子文件)
markdown.css 16KB
player.css 11KB
index.css 9KB
client.css 4KB
iconfont.css 2KB
iconfont.css 2KB
index.css 1KB
playermobile.css 0B
.env.development 233B
.env.development 233B
.editorconfig 540B
.editorconfig 78B
iconfont.eot 12KB
iconfont.eot 10KB
iconfont.eot 9KB
.eslintrc 1022B
local.html 2KB
index.html 1KB
index.html 672B
index.html 550B
favicon.ico 18KB
favicon.ico 18KB
solarBlog-server.iml 17KB
ArticleServiceImpl.java 15KB
RedisService.java 10KB
UserAuthServiceImpl.java 10KB
CommentServiceImpl.java 9KB
RedisServiceImpl.java 9KB
BlogInfoServiceImpl.java 9KB
MenuServiceImpl.java 8KB
ResourceServiceImpl.java 8KB
WebSocketServiceImpl.java 8KB
AbstractSocialLoginStrategyImpl.java 6KB
ArticleController.java 6KB
UserInfoServiceImpl.java 6KB
PhotoServiceImpl.java 6KB
BlogInfoController.java 6KB
SensitiveUtils.java 6KB
RoleServiceImpl.java 5KB
WebSecurityConfig.java 5KB
WeiboLoginStrategyImpl.java 5KB
SiteNavServiceImpl.java 5KB
QQLoginStrategyImpl.java 5KB
PhotoAlbumServiceImpl.java 5KB
WebsiteConfigVO.java 4KB
EsSearchStrategyImpl.java 4KB
PhotoAlbumController.java 4KB
UserAuthController.java 4KB
UserDetailsServiceImpl.java 4KB
PhotoController.java 4KB
MessageServiceImpl.java 4KB
OptLogAspect.java 4KB
CategoryServiceImpl.java 4KB
CommentController.java 4KB
UserInfoController.java 4KB
TagServiceImpl.java 3KB
SiteNavController.java 3KB
IpUtils.java 3KB
CategoryController.java 3KB
MySqlSearchStrategyImpl.java 3KB
FilterInvocationSecurityMetadataSourceImpl.java 3KB
FileUtils.java 3KB
MessageController.java 3KB
TagController.java 3KB
UserDetailDTO.java 3KB
FriendLinkController.java 2KB
AuthenticationFailHandlerImpl.java 2KB
MenuController.java 2KB
Result.java 2KB
LogController.java 2KB
ResourceController.java 2KB
ConditionVO.java 2KB
AuthenticationSuccessHandlerImpl.java 2KB
FriendLinkServiceImpl.java 2KB
UniqueViewServiceImpl.java 2KB
RoleController.java 2KB
OssUploadStrategyImpl.java 2KB
LocalUploadStrategyImpl.java 2KB
ArticleService.java 2KB
CommentMapper.java 2KB
wxLoginStrategyImpl.java 2KB
AbstractUploadStrategyImpl.java 2KB
ArticleVO.java 2KB
ArticleMapper.java 2KB
PageServiceImpl.java 2KB
VoiceVO.java 2KB
RedisConfig.java 2KB
PageController.java 2KB
EmailConsumer.java 2KB
MenuVO.java 2KB
UserAuthService.java 2KB
LoginLogServiceImpl.java 2KB
OperationLogServiceImpl.java 2KB
SiteNavVO.java 2KB
SwaggerConfig.java 2KB
LoginLog.java 2KB
ArticleDTO.java 2KB
MaxWellConsumer.java 2KB
RedisPrefixConst.java 2KB
LoginLogDTO.java 2KB
共 1382 条
- 1
- 2
- 3
- 4
- 5
- 6
- 14
资源评论
Yuki-^_^
- 粉丝: 3101
- 资源: 2837
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- ccceeeeee,ukytkyk/liyihm
- 考虑新能源消纳的火电机组深度调峰策略 摘要:本代码主要做的是考虑新能源消纳的火电机组深度调峰策略,以常规调峰、不投油深度调峰、投油深度调峰三个阶段,建立了火电机组深度调峰成本模型,并以风电全额消纳为前
- PROGPPCNEXUS读写烧录刷写软件 飞思卡尔MPC55xx 56xx 57xx 58xx 没有次数限制
- 含光伏的储能选址定容模型 14节点 程序采用改进粒子群算法,对分析14节点配网系统中的储能选址定容方案,并得到储能的出力情况,有相关参考资料 这段程序是一个粒子群算法(Particle Swarm O
- P6ProfessionalSetup R24.12 安装包
- SQLServer2012数据库配置及网络连接设置WORD文档doc格式最新版本
- 中大型三相异步电机电磁设计软件
- DSP28335 PMSM电机控制程序
- 四足机器人技术发展及其应用场景概述
- linux常用命令大全.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功