fix(file-transfer): centralize dir-list page token parsing · openclaw/openclaw@1951413
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
File tree
extensions/file-transfer/src/node-host
| Original file line number | Diff line number | Diff line change |
|---|
@@ -144,6 +144,19 @@ describe("handleDirList — happy path", () => {
|
144 | 144 | expect(r.entries.map((e) => e.name)).toEqual(["f-0.txt"]); |
145 | 145 | expect(r.nextPageToken).toBe("1"); |
146 | 146 | }); |
| 147 | + |
| 148 | +it("accepts plus-signed page tokens", async () => { |
| 149 | +for (let i = 0; i < 3; i++) { |
| 150 | +await fs.writeFile(path.join(tmpRoot, `f-${i}.txt`), "x"); |
| 151 | +} |
| 152 | + |
| 153 | +const r = await handleDirList({ path: tmpRoot, maxEntries: 1, pageToken: "+01" }); |
| 154 | +if (!r.ok) { |
| 155 | +throw new Error("expected ok"); |
| 156 | +} |
| 157 | +expect(r.entries.map((e) => e.name)).toEqual(["f-1.txt"]); |
| 158 | +expect(r.nextPageToken).toBe("2"); |
| 159 | +}); |
147 | 160 | }); |
148 | 161 | |
149 | 162 | describe("handleDirList — limits", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import path from "node:path"; |
| 2 | +import { parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime"; |
2 | 3 | import { root } from "openclaw/plugin-sdk/security-runtime"; |
3 | 4 | import { mimeFromExtension } from "../shared/mime.js"; |
4 | 5 | import { |
@@ -63,12 +64,7 @@ function parsePageOffset(input: unknown): number {
|
63 | 64 | if (typeof input !== "string") { |
64 | 65 | return 0; |
65 | 66 | } |
66 | | -const trimmed = input.trim(); |
67 | | -if (!/^\d+$/.test(trimmed)) { |
68 | | -return 0; |
69 | | -} |
70 | | -const offset = Number(trimmed); |
71 | | -return Number.isSafeInteger(offset) ? offset : 0; |
| 67 | +return parseStrictNonNegativeInteger(input) ?? 0; |
72 | 68 | } |
73 | 69 | |
74 | 70 | function classifyFsError(err: unknown): DirListErrCode { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。