fix(synology-chat): centralize user id parsing · openclaw/openclaw@3dfb76f
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
File tree
extensions/synology-chat/src
| Original file line number | Diff line number | Diff line change |
|---|
@@ -191,6 +191,25 @@ describe("sendMessage", () => {
|
191 | 191 | expect(payload).toEqual({ text: "Hello" }); |
192 | 192 | }); |
193 | 193 | |
| 194 | +it("accepts plus-signed numeric user ids", async () => { |
| 195 | +mockSuccessResponse(); |
| 196 | +await settleTimers(sendMessage("https://nas.example.com/incoming", "Hello", "+042")); |
| 197 | + |
| 198 | +const request = vi.mocked(https.request).mock.results[0]?.value as ClientRequest | undefined; |
| 199 | +if (!request) { |
| 200 | +throw new Error("expected Synology Chat webhook request"); |
| 201 | +} |
| 202 | +const body = vi.mocked(request.write).mock.calls[0]?.[0]; |
| 203 | +if (typeof body !== "string") { |
| 204 | +throw new Error("expected Synology Chat webhook body"); |
| 205 | +} |
| 206 | +const payload = JSON.parse(decodeURIComponent(body.replace(/^payload=/, ""))) as Record< |
| 207 | +string, |
| 208 | +unknown |
| 209 | +>; |
| 210 | +expect(payload).toEqual({ text: "Hello", user_ids: [42] }); |
| 211 | +}); |
| 212 | + |
194 | 213 | it("only disables TLS verification when explicitly requested", async () => { |
195 | 214 | mockSuccessResponse(); |
196 | 215 | await settleTimers(sendMessage("https://nas.example.com/incoming", "Hello", undefined, true)); |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6,6 +6,7 @@
|
6 | 6 | import * as http from "node:http"; |
7 | 7 | import * as https from "node:https"; |
8 | 8 | import { safeParseJsonWithSchema, safeParseWithSchema } from "openclaw/plugin-sdk/extension-shared"; |
| 9 | +import { parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime"; |
9 | 10 | import { sleep } from "openclaw/plugin-sdk/runtime-env"; |
10 | 11 | import { |
11 | 12 | formatErrorMessage, |
@@ -295,12 +296,7 @@ function parseNumericUserId(userId?: string | number): number | undefined {
|
295 | 296 | if (typeof userId === "number") { |
296 | 297 | return Number.isSafeInteger(userId) ? userId : undefined; |
297 | 298 | } |
298 | | -const trimmed = userId.trim(); |
299 | | -if (!/^\d+$/.test(trimmed)) { |
300 | | -return undefined; |
301 | | -} |
302 | | -const numericId = Number(trimmed); |
303 | | -return Number.isSafeInteger(numericId) ? numericId : undefined; |
| 299 | +return parseStrictNonNegativeInteger(userId); |
304 | 300 | } |
305 | 301 | |
306 | 302 | function doPost(url: string, body: string, allowInsecureSsl = false): Promise<boolean> { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。