-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
1,079 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
on: push | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
- run: npm ci | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import chai from 'chai' | ||
import qs from 'qs' | ||
import parse from '../index.mjs' | ||
|
||
describe('parse', () => { | ||
it('array', () => { | ||
chai.expect(parse('a[]&a[]&a[]&a[]&a[]&a[]')).to.be.deep.equal({ | ||
a: ['', '', '', '', '', ''], | ||
}) | ||
chai.expect(parse('a&a&a&a[]&a[]&a[]')).to.be.deep.equal({ | ||
a: ['', '', '', '', '', ''], | ||
}) | ||
}) | ||
|
||
it('nested array', () => { | ||
chai.expect(parse('a[][][]&a[][][]&a[][][]&a[][]&a[][]&a[]')).to.be.deep.equal({ | ||
a: [[['', '', '']], ['', ''], ''], | ||
}) | ||
}) | ||
|
||
it('array with index', () => { | ||
chai.expect(parse('a[3]=3&a[5]=5&a[2]=2&a[4]=4&a[1]=1&a[0]=0&a[10]=10')).to.be.deep.equal({ | ||
a: ['0', '1', '2', '3', '4', '5', undefined, undefined, undefined, undefined, '10'], | ||
}) | ||
}) | ||
|
||
it('object', () => { | ||
chai.expect(parse('a[a]&a[b]&a[c]')).to.be.deep.equal({ | ||
a: { a: '', b: '', c: '' }, | ||
}) | ||
}) | ||
|
||
it('nested object', () => { | ||
chai.expect(parse('a[a][a]&a[a][b]&a[a][c]')).to.be.deep.equal({ | ||
a: { a: { a: '', b: '', c: '' } }, | ||
}) | ||
}) | ||
|
||
it('drop insecure key', () => { | ||
chai.expect(parse('a[constructor][prototype][a]=1')).to.be.deep.equal({ | ||
a: undefined, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.