w3c / webvtt.js

WebVTT parser and validator
https://w3c.github.io/webvtt.js/parser.html
Creative Commons Zero v1.0 Universal
146 stars 49 forks source link

Fix serialising of one or two digit millisecond values #33

Closed davemevans closed 2 years ago

davemevans commented 3 years ago

There's a bug in serializeTimestamp that assumes that millisecond values should always be end-padded with zeros up to three digits. This isn't true when milliseconds is less than 100, since these need to be start-padded with at least one zero to maintain their meaning.

Rather than try to find a clever solution, I opted for the old prepend-zeroes-and-slice trick.

Consider the following cue:

00:53.920 --> 00:59.040
Just some random text

This will currently be incorrectly serialised as :

00:53.920 --> 00:59.400
Just some random text