[dynamicjson] Fix unexpected token in JSONPath query (#4984)

Includes a test.

Fixes #4988
This commit is contained in:
Paul Melnikow
2020-04-30 23:19:39 -04:00
committed by GitHub
parent 612a43aaa9
commit 5b42c8310b
2 changed files with 17 additions and 1 deletions

View File

@@ -160,6 +160,21 @@ t.create('query with parse error')
color: 'red',
})
// Example from https://stackoverflow.com/q/11670384/893113
const badQuery =
"$[?(en|**|(@.object.property.one=='other') && (@.object.property.two=='something(abc/def)'))]"
t.create('query with invalid token')
.get(
`.json?url=https://github.com/badges/shields/raw/master/package.json&query=${encodeURIComponent(
badQuery
)}`
)
.expectBadge({
label: 'custom badge',
message: 'unparseable jsonpath query',
color: 'red',
})
t.create('JSON contains an array')
.get('.json?url=https://example.test/json&query=$[0]')
.intercept(nock =>

View File

@@ -67,7 +67,8 @@ module.exports = superclass =>
const { message } = e
if (
message.startsWith('Lexical error') ||
message.startsWith('Parse error')
message.startsWith('Parse error') ||
message.includes('Unexpected token')
) {
throw new InvalidParameter({
prettyMessage: 'unparseable jsonpath query',