Skip to content

Commit

Permalink
catch queries that cause TypeError (#10556)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris48s authored Sep 30, 2024
1 parent 0f14eed commit da60020
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 15 additions & 2 deletions services/dynamic/dynamic-json.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,25 @@ t.create('query with parse error')
})

// Example from https://stackoverflow.com/q/11670384/893113
const badQuery =
const invalidTokenQuery =
"$[?(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,
invalidTokenQuery,
)}`,
)
.expectBadge({
label: 'custom badge',
message: 'query not supported',
color: 'red',
})

const invalidEscapequery = "$.definitions.common.properties.['@id'].format"
t.create('query with invalid escape')
.get(
`.json?url=https://raw.githubusercontent.com/json-ld/json-ld.org/refs/heads/main/schemas/jsonld-schema.json&query=${encodeURIComponent(
invalidEscapequery,
)}`,
)
.expectBadge({
Expand Down
5 changes: 4 additions & 1 deletion services/dynamic/json-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export default superclass =>
values = jp({ json: data, path: pathExpression, eval: false })
} catch (e) {
const { message } = e
if (message.includes('prevented in JSONPath expression')) {
if (
message.includes('prevented in JSONPath expression') ||
e instanceof TypeError
) {
throw new InvalidParameter({
prettyMessage: 'query not supported',
})
Expand Down

0 comments on commit da60020

Please sign in to comment.