glut23 / webvtt-py

Read, write, convert and segment WebVTT caption files in Python.
MIT License
192 stars 56 forks source link

Fix invalid escape sequence #50

Closed abdnh closed 7 months ago

andruekonst commented 7 months ago

In some modern environments the following exception can occur:

       TIMESTAMP_PATTERN = re.compile('(\d+)?:?(\d{2}):(\d{2})[.,](\d{3})')
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   SyntaxError: invalid escape sequence '\d'

Indeed, the exception is correct, because \d is not a valid escape sequence. But this aspect is usually ignored by interpreters and had caused no exceptions, approximately till 3.11.4.

The solution would be to add r literal:

TIMESTAMP_PATTERN = re.compile(r'(\d+)?:?(\d{2}):(\d{2})[.,](\d{3})')

Why this PR is not merged?

glut23 commented 7 months ago

Hey @andruekonst apologies for having this PR seating opened there forever. It is now merged.