The best way to control Claude Code, Codex and more from any computer or phone
fix(server): avoid excessive backtracking in webhook templates (#19160)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com>
Simone committed
Oct 14, 2026 at 04:34 UTC
5e5abc92f472d764f232316d41f33e9159b81056
2 files changed
+23
-2
apps/server/src/scheduledTasks/webhookTemplate.test.ts
+19
@@ -52,6 +52,25 @@ describe("renderWebhookPrompt", () => {
52
assert.deepEqual(rendered.missing, ["body.nope", "headers.x-missing", "unknown"]);
53
});
54
55
+ it("trims placeholder whitespace before resolving and reporting missing fields", () => {
56
+ const rendered = renderWebhookPrompt(
57
+ "{{\tbody.action\n}}|{{ body.nope }}|{{\nbody.nope\t}}|{{ \t\n }}",
58
+ githubPullRequest,
59
+ );
60
+ assert.equal(rendered.prompt, "opened|||");
61
+ assert.deepEqual(rendered.missing, ["body.nope", ""]);
62
+ });
63
+
64
+ it("preserves unclosed whitespace-heavy placeholders and resolves later valid ones", () => {
65
+ const unfinished = `Notify {{${" ".repeat(1024)}body`;
66
+ const rendered = renderWebhookPrompt(
67
+ `${unfinished}\n{{body.pull_request.number}}`,
68
+ githubPullRequest,
69
+ );
70
+ assert.equal(rendered.prompt, `${unfinished}\n45`);
71
+ assert.deepEqual(rendered.missing, []);
72
+ });
73
+
74
it("addresses form-encoded bodies and leaves other bodies to {{body}}", () => {
75
const form = renderWebhookPrompt("{{body.text}} by {{body.user_name}}", {
76
...githubPullRequest,
apps/server/src/scheduledTasks/webhookTemplate.ts
+4
-2
@@ -69,7 +69,8 @@ export function redactQuery(query: string): string {
69
.join("&");
70
}
71
72
-const PLACEHOLDER = /\{\{\s*([^{}]*?)\s*\}\}/g;
72
+// Trim after matching so unclosed placeholders cannot backtrack over whitespace partitions.
73
+const PLACEHOLDER = /\{\{([^{}]*)\}\}/g;
74
75
function parseBody(request: WebhookRequest): unknown {
76
const contentType = (request.headers["content-type"] ?? "").toLowerCase();
@@ -144,7 +145,8 @@ export function renderWebhookPrompt(
145
}
146
};
147
147
- const prompt = template.replace(PLACEHOLDER, (_match, expression: string) => {
148
+ const prompt = template.replace(PLACEHOLDER, (_match, rawExpression: string) => {
149
+ const expression = rawExpression.trim();
150
const value = resolve(expression);
151
if (value === undefined || value === null) {
152
if (!missing.includes(expression)) missing.push(expression);