branch: elpa/subed commit dc60c27e16e34f6f60c97f5b852ef27f42c4e456 Author: Random User <rnd...@posteo.de> Commit: Random User <rnd...@posteo.de>
subed-srt--subtitle-id-at-msecs: Try to ignore invalid time stamps --- subed/subed-srt.el | 4 ++-- tests/test-subed-srt.el | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/subed/subed-srt.el b/subed/subed-srt.el index 5078deb..8a7d506 100644 --- a/subed/subed-srt.el +++ b/subed/subed-srt.el @@ -83,12 +83,12 @@ after MSECS if there is one and its start time is >= MSECS + (re-search-forward (format "\\(\n\n\\|\\`\\)[0-9]+\n%02d:%02d" only-hours only-mins) nil t))) ;; Move to first subtitle that starts at or after MSECS (catch 'last-subtitle-reached - (while (<= (subed-srt--subtitle-msecs-start) msecs) + (while (<= (or (subed-srt--subtitle-msecs-start) -1) msecs) (unless (subed-srt-forward-subtitle-id) (throw 'last-subtitle-reached nil)))) ;; Move back to previous subtitle if start of current subtitle is in the ;; future (i.e. MSECS is between subtitles) - (when (> (subed-srt--subtitle-msecs-start) msecs) + (when (> (or (subed-srt--subtitle-msecs-start) -1) msecs) (subed-srt-backward-subtitle-id)) (subed-srt--subtitle-id)))) diff --git a/tests/test-subed-srt.el b/tests/test-subed-srt.el index 044054e..129b001 100644 --- a/tests/test-subed-srt.el +++ b/tests/test-subed-srt.el @@ -88,6 +88,14 @@ Baz. (progn (subed-srt-move-to-subtitle-id outset-id) (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal target-id))))))) + (it "doesn't fail when start time is invalid." + (with-temp-buffer + (insert mock-srt-data) + (subed-srt-move-to-subtitle-id 2) + (let ((msecs (- (subed-srt--subtitle-msecs-start) 1))) + (subed-srt-move-to-subtitle-time-start) + (forward-char 8) (delete-char 1) + (expect (subed-srt--subtitle-id-at-msecs msecs) :to-equal 2)))) ) (describe "the subtitle start/stop time" (it "returns the time in milliseconds."