-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qs.parse returns invalid key with brackets when using nested array qu…
…ery (#1751) * add test to fix nested query * add fix to account for limitations of qs.parse * Add assertion for key wrapped in square brackets * update qs library that includes strictDepth=true * Revert "add test to fix nested query" This reverts commit a3ea344. * remove previous fix that manually changes the key. Just use qs configuration * add qs-test module * fix lint * update ts-expect-error for missing strictDepth type * fix spacing * Upgrade @types/qs to include strictDepth
- Loading branch information
1 parent
8168783
commit e8a6ec9
Showing
7 changed files
with
135 additions
and
70 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
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,54 @@ | ||
import qs from 'qs'; | ||
import { module, test } from 'qunit'; | ||
|
||
import { parseQuery, Query } from '@cardstack/runtime-common/query'; | ||
|
||
module('Unit | qs | parse', function () { | ||
test('parseQuery errors out if the query is too deep', async function (assert) { | ||
assert.throws( | ||
() => parseQuery('a[b][c][d][e][f][g][h][i][j][k][l]=m'), | ||
/RangeError: Input depth exceeded depth option of 10 and strictDepth is true/, | ||
); | ||
}); | ||
test('invertibility: applying stringify and parse on object will return the same object', async function (assert) { | ||
let testRealmURL = 'https://example.com/'; | ||
let query: Query = { | ||
filter: { | ||
on: { | ||
module: `${testRealmURL}book`, | ||
name: 'Book', | ||
}, | ||
every: [ | ||
{ | ||
eq: { | ||
'author.firstName': 'Cardy', | ||
}, | ||
}, | ||
{ | ||
any: [ | ||
{ | ||
eq: { | ||
'author.lastName': 'Jones', | ||
}, | ||
}, | ||
{ | ||
eq: { | ||
'author.lastName': 'Stackington Jr. III', | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
sort: [ | ||
{ | ||
by: 'author.lastName', | ||
on: { module: `${testRealmURL}book`, name: 'Book' }, | ||
}, | ||
], | ||
}; | ||
let queryString = qs.stringify(query); | ||
let parsedQuery: any = parseQuery(queryString); | ||
assert.deepEqual(parsedQuery, query); | ||
}); | ||
}); |
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
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
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
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.