Skip to content

Commit 1528f6d

Browse files
fix(parser): reject unit-less timestamps that are not numbers (#2732)
1 parent 11fe3f7 commit 1528f6d

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

packages/parser/src/timesplit/timestring.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ describe('parseTimeString', () => {
2020
expect(() => parseTimeString('10x')).toThrow('Invalid timestamp unit: x')
2121
expect(() => parseTimeString('10h:10m:10s')).toThrow('Invalid timestamp format')
2222
expect(() => parseTimeString('hello 1s world')).toThrow('Unknown timestamp remaining: hello world')
23+
// A unit-less value that isn't a number used to fall through to `Number()`
24+
// and yield NaN, which then spread silently into the timer and timesplits.
25+
expect(() => parseTimeString('30,5')).toThrow('Invalid timestamp format')
26+
expect(() => parseTimeString('1 30')).toThrow('Invalid timestamp format')
27+
expect(() => parseTimeString('1.2.3')).toThrow('Invalid timestamp format')
2328
})
2429
})

packages/parser/src/timesplit/timestring.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export function parseTimeString(timestamp: string | number): {
5858
}
5959
else if (!RE_ALPHA.test(timestamp)) {
6060
seconds = Number(timestamp)
61+
if (Number.isNaN(seconds)) {
62+
throw new TypeError('Invalid timestamp format')
63+
}
6164
}
6265
else {
6366
const unitMap: Record<string, number> = {

0 commit comments

Comments
 (0)