File tree Expand file tree Collapse file tree
packages/parser/src/timesplit Expand file tree Collapse file tree Original file line number Diff line number Diff 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} )
Original file line number Diff line number Diff 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 > = {
You can’t perform that action at this time.
0 commit comments