






















@@ -37,7 +37,7 @@ import { applyMatrixProfileUpdate } from "./profile-update.js";
3737import {
3838createActionGate,
3939jsonResult,
40-readNumberParam,
40+readPositiveIntegerParam,
4141readReactionParams,
4242readStringArrayParam,
4343readStringParam,
@@ -118,33 +118,29 @@ function readStringAliasParam(
118118return undefined;
119119}
120120121-function readNumericArrayParam(
122-params: Record<string, unknown>,
123-key: string,
124-options: { integer?: boolean } = {},
125-): number[] {
126-const { integer = false } = options;
121+function readPositiveIntegerArrayParam(params: Record<string, unknown>, key: string): number[] {
127122const raw = readRawParam(params, key);
128-if (raw === undefined) {
123+if (raw == null) {
129124return [];
130125}
131-return (Array.isArray(raw) ? raw : [raw])
132-.map((value) => {
133-if (typeof value === "number" && Number.isFinite(value)) {
134-return value;
126+return (Array.isArray(raw) ? raw : [raw]).flatMap((value) => {
127+if (value == null || value === "") {
128+return [];
129+}
130+if (typeof value === "string") {
131+const trimmed = value.trim();
132+if (!trimmed) {
133+return [];
135134}
136-if (typeof value === "string") {
137-const trimmed = value.trim();
138-if (!trimmed) {
139-return null;
140-}
141-const parsed = Number(trimmed);
142-return Number.isFinite(parsed) ? parsed : null;
135+if (!/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:e[+-]?\d+)?$/i.test(trimmed)) {
136+return [];
143137}
144-return null;
145-})
146-.filter((value): value is number => value !== null)
147-.map((value) => (integer ? Math.trunc(value) : value));
138+}
139+const index = readPositiveIntegerParam({ [key]: value }, key, {
140+message: `${key} must contain positive integers.`,
141+});
142+return index === undefined ? [] : [index];
143+});
148144}
149145150146export async function handleMatrixAction(
@@ -180,7 +176,9 @@ export async function handleMatrixAction(
180176await reactMatrixMessage(roomId, messageId, emoji, clientOpts);
181177return jsonResult({ ok: true, added: emoji });
182178}
183-const limit = readNumberParam(params, "limit", { integer: true });
179+const limit = readPositiveIntegerParam(params, "limit", {
180+message: "limit must be a positive integer.",
181+});
184182const reactions = await listMatrixReactions(roomId, messageId, {
185183 ...clientOpts,
186184limit: limit ?? undefined,
@@ -195,13 +193,15 @@ export async function handleMatrixAction(
195193throw new Error("pollId required");
196194}
197195const optionId = readStringParam(params, "pollOptionId");
198-const optionIndex = readNumberParam(params, "pollOptionIndex", { integer: true });
196+const optionIndex = readPositiveIntegerParam(params, "pollOptionIndex", {
197+message: "pollOptionIndex must be a positive integer.",
198+});
199199const optionIds = [
200200 ...(readStringArrayParam(params, "pollOptionIds") ?? []),
201201 ...(optionId ? [optionId] : []),
202202];
203203const optionIndexes = [
204- ...readNumericArrayParam(params, "pollOptionIndexes", { integer: true }),
204+ ...readPositiveIntegerArrayParam(params, "pollOptionIndexes"),
205205 ...(optionIndex !== undefined ? [optionIndex] : []),
206206];
207207const result = await voteMatrixPoll(roomId, pollId, {
@@ -266,7 +266,9 @@ export async function handleMatrixAction(
266266}
267267case "readMessages": {
268268const roomId = readRoomId(params);
269-const limit = readNumberParam(params, "limit", { integer: true });
269+const limit = readPositiveIntegerParam(params, "limit", {
270+message: "limit must be a positive integer.",
271+});
270272const before = readStringParam(params, "before");
271273const after = readStringParam(params, "after");
272274const result = await readMatrixMessages(roomId, {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。