diff --git a/apps/server/src/scheduledTasks/webhookFilter.test.ts b/apps/server/src/scheduledTasks/webhookFilter.test.ts index 2c7f2cc4062e8..3fdd9accd01c6 100644 --- a/apps/server/src/scheduledTasks/webhookFilter.test.ts +++ b/apps/server/src/scheduledTasks/webhookFilter.test.ts @@ -89,6 +89,12 @@ describe("findFailedWebhookFilter", () => { issueComment, ), ); + assert.isNull( + findFailedWebhookFilter( + [{ path: "body.issue.assignees[].login", op: "notEquals", value: "anyone" }], + { ...issueComment, bodyText: JSON.stringify({ issue: { assignees: null } }) }, + ), + ); assert.deepEqual( findFailedWebhookFilter([{ path: "body.issue.number[].x", op: "exists" }], issueComment), { index: 0, path: "body.issue.number[].x" }, diff --git a/apps/server/src/scheduledTasks/webhookTemplate.ts b/apps/server/src/scheduledTasks/webhookTemplate.ts index fc43dbff921ed..233e765da86b5 100644 --- a/apps/server/src/scheduledTasks/webhookTemplate.ts +++ b/apps/server/src/scheduledTasks/webhookTemplate.ts @@ -67,10 +67,10 @@ function parseBody(request: WebhookRequest): unknown { const WILDCARD = /^(.*)\[\]$/; /** - * Walks `segments` from `root`. A segment ending in `[]` names an array and - * the rest of the path applies to each element, so `labels[].name` resolves - * to the list of every label's name. Elements without the rest of the path - * are dropped; a wildcard on a non-array resolves to undefined. + * Walks `segments` from `root`; a `[]` segment applies the rest of the path to + * each array element, dropping elements that lack it. A wildcard on null is an + * empty list, as Go senders such as Forgejo encode one, and on any other + * non-array it is undefined. */ function lookup(root: unknown, segments: ReadonlyArray): unknown { let current = root; @@ -81,6 +81,7 @@ function lookup(root: unknown, segments: ReadonlyArray): unknown { if (!Object.hasOwn(current, key)) return undefined; current = (current as Record)[key]; if (!wildcard) continue; + if (current === null) return []; if (!Array.isArray(current)) return undefined; const rest = segments.slice(index + 1); return current.flatMap((element) => {