fix(msteams): centralize poll selection parsing · openclaw/openclaw@2be1d1b
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -81,6 +81,22 @@ describe("msteams polls", () => {
|
81 | 81 | ), |
82 | 82 | ).toEqual(["0"]); |
83 | 83 | }); |
| 84 | + |
| 85 | +it("accepts only strict decimal poll selections", () => { |
| 86 | +expect( |
| 87 | +normalizeMSTeamsPollSelections( |
| 88 | +{ |
| 89 | +id: "poll-1", |
| 90 | +question: "Lunch?", |
| 91 | +options: ["Pizza", "Sushi"], |
| 92 | +maxSelections: 2, |
| 93 | +votes: {}, |
| 94 | +createdAt: "2026-03-22T00:00:00.000Z", |
| 95 | +}, |
| 96 | +["+0", "0x1", "1"], |
| 97 | +), |
| 98 | +).toEqual(["0", "1"]); |
| 99 | +}); |
84 | 100 | }); |
85 | 101 | |
86 | 102 | const createFsStore = async () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import crypto from "node:crypto"; |
| 2 | +import { parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime"; |
2 | 3 | import { |
3 | 4 | isRecord, |
4 | 5 | normalizeOptionalString, |
@@ -256,11 +257,8 @@ function pruneToLimit(polls: Record<string, MSTeamsPoll>) {
|
256 | 257 | export function normalizeMSTeamsPollSelections(poll: MSTeamsPoll, selections: string[]) { |
257 | 258 | const maxSelections = Math.max(1, poll.maxSelections); |
258 | 259 | const mapped = selections |
259 | | -.map((entry) => { |
260 | | -const trimmed = entry.trim(); |
261 | | -return /^\d+$/.test(trimmed) ? Number(trimmed) : Number.NaN; |
262 | | -}) |
263 | | -.filter((value) => Number.isSafeInteger(value)) |
| 260 | +.map((entry) => parseStrictNonNegativeInteger(entry)) |
| 261 | +.filter((value): value is number => value !== undefined) |
264 | 262 | .filter((value) => value >= 0 && value < poll.options.length) |
265 | 263 | .map((value) => String(value)); |
266 | 264 | const limited = maxSelections > 1 ? mapped.slice(0, maxSelections) : mapped.slice(0, 1); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。