Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/python/ttconv/scc/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
'(?P<ndf_m>[0-9]{2})',
'(?P<ndf_s>[0-9]{2})',
'(?P<ndf_f>[0-9]{2})'])
DF_PATTERN = '(:|;|.|,)'.join(['(?P<df_h>[0-9]{2})',
DF_PATTERN = '[:;.,]'.join(['(?P<df_h>[0-9]{2})',
'(?P<df_m>[0-9]{2})',
'(?P<df_s>[0-9]{2})',
'(?P<df_f>[0-9]{2})'])
Expand Down
6 changes: 3 additions & 3 deletions src/main/python/ttconv/time_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class SmpteTimeCode(_HHMMSSTimeExpression):

_NDF_TC_RE = re.compile(_NDF_TC_PATTERN)

_DF_TC_PATTERN = '(:|;|.|,)'.join(['(?P<df_h>[0-9]{2})',
_DF_TC_PATTERN = '[:;.,]'.join(['(?P<df_h>[0-9]{2})',
'(?P<df_m>[0-9]{2})',
'(?P<df_s>[0-9]{2})',
'(?P<df_f>[0-9]{2})'])
Expand Down Expand Up @@ -222,7 +222,7 @@ def add_frames(self, nb_frames=1):
def parse(time_code: str, frame_rate: Fraction) -> SmpteTimeCode:
"""Reads the time code string and converts to a SmpteTimeCode instance"""

match = SmpteTimeCode._NDF_TC_RE.match(time_code)
match = SmpteTimeCode._NDF_TC_RE.fullmatch(time_code)

if match is not None:
# NDF timecode
Expand All @@ -236,7 +236,7 @@ def parse(time_code: str, frame_rate: Fraction) -> SmpteTimeCode:
if frame_rate.denominator != 1001:
frame_rate = frame_rate * Fraction(1000, 1001)

match = SmpteTimeCode.DF_TC_RE.match(time_code)
match = SmpteTimeCode.DF_TC_RE.fullmatch(time_code)

if match is not None:
return SmpteTimeCode(int(match.group('df_h')),
Expand Down
8 changes: 8 additions & 0 deletions src/test/python/test_time_code_smpte.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ def test_parse_drop_frame_time_code(self):
self.assertEqual(Fraction(111582, Fraction(30000, 1001)), time_code.to_temporal_offset())
self.assertEqual("01:02:03;04", str(time_code))

def test_parse_rejects_invalid_time_code(self):
# the separator alternation used to include an unescaped '.', which matches
# any character, and matching was not anchored to the end of the string
for time_code in ["01x02x03x04", "01 02-03/04", "01:02:03:04garbage", "01:02:03.456"]:
with self.subTest(time_code=time_code):
with self.assertRaises(ValueError):
SmpteTimeCode.parse(time_code, FPS_29_97)

def test_time_code_frames_conversion(self):
time_code = SmpteTimeCode.from_frames(1795, FPS_30)
self.assertEqual("00:00:59:25", str(time_code))
Expand Down