Skip to content

Commit 8f1c08e

Browse files
ryanioclaude
andauthored
fix(utils): reject whitespace in decodeTokenIds with helpful error (#1865)
Add explicit check for whitespace that throws a clear error message showing the expected format: '1,2,3' or '1:5' or '1,3:5,8' (no spaces). Co-authored-by: Claude Opus 4.5 <[email protected]>
1 parent 00e9cca commit 8f1c08e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/utils/protocol.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ export const decodeTokenIds = (encodedTokenIds: string): string[] => {
140140
return [];
141141
}
142142

143+
// Check for whitespace and provide helpful error message
144+
if (/\s/.test(encodedTokenIds)) {
145+
throw new Error(
146+
"Invalid input format: whitespace is not allowed. Expected format: '1,2,3' or '1:5' or '1,3:5,8' (no spaces).",
147+
);
148+
}
149+
143150
const validFormatRegex = /^(\d+(:\d+)?)(,\d+(:\d+)?)*$/;
144151

145152
if (!validFormatRegex.test(encodedTokenIds)) {

test/utils/protocol.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ suite("Utils: protocol", () => {
211211
test("correctly decodes range where start = end", () => {
212212
expect(decodeTokenIds("5:5")).to.deep.equal(["5"]);
213213
});
214+
215+
test("throws error for input with whitespace", () => {
216+
expect(() => decodeTokenIds(" 1,2,3")).to.throw(
217+
"whitespace is not allowed",
218+
);
219+
expect(() => decodeTokenIds("1 : 3")).to.throw(
220+
"whitespace is not allowed",
221+
);
222+
expect(() => decodeTokenIds("1, 2")).to.throw(
223+
"whitespace is not allowed",
224+
);
225+
});
214226
});
215227

216228
suite("getSeaportInstance", () => {

0 commit comments

Comments
 (0)