Skip to content

Commit 36cc7b6

Browse files
committed
♻️ Add input validation to helper function (#1807)
1 parent dedab98 commit 36cc7b6

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/lib/utils/contest_table_provider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,14 @@ class ABC212ToABC318Provider extends ContestTableProviderBase {
165165
}
166166

167167
function parseContestRound(contestId: string, prefix: string): number {
168-
return parseInt(contestId.replace(prefix, ''), 10);
168+
const withoutPrefix = contestId.replace(prefix, '');
169+
170+
// Verify the prefix was present and the remaining string is numeric
171+
if (withoutPrefix === contestId || !/^\d+$/.test(withoutPrefix)) {
172+
throw new Error(`Invalid contest id has given: ${contestId}`);
173+
}
174+
175+
return parseInt(withoutPrefix, 10);
169176
}
170177

171178
// TODO: Add providers for other contest types if needs.

0 commit comments

Comments
 (0)