summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-02-07 16:05:10 -0500
committerDavid Thompson <dthompson2@worcester.edu>2015-02-07 16:05:10 -0500
commit0ef9ff4a17cc4a2311dfa8f91ed06eba8730daab (patch)
treedb3aac4c0d94c9d3e3a05ca2f2fe7a7108634751
parentb965a6d6326e67df0b0909065119c59563da8db2 (diff)
subrip: Throw errors when reading invalid timestamps.
* srt2vtt/subrip.scm (parse-time, parse-time-span): Throw error when regexp doesn't match.
-rw-r--r--srt2vtt/subrip.scm14
1 files changed, 9 insertions, 5 deletions
diff --git a/srt2vtt/subrip.scm b/srt2vtt/subrip.scm
index 167aff8..44f118e 100644
--- a/srt2vtt/subrip.scm
+++ b/srt2vtt/subrip.scm
@@ -26,22 +26,26 @@
read-subrips))
(define parse-time
- (let ((regexp (make-regexp "([0-9]+):([0-9]+):([0-9]+),([0-9]+)")))
+ (let ((regexp (make-regexp "^([0-9]+):([0-9]+):([0-9]+),([0-9]+)$")))
(lambda (s)
"Parse the SubRip formatted timestamp in the string S into a 4
element list. Valid input looks like '00:00:03.417'."
(let ((match (regexp-exec regexp s)))
- (map (cut match:substring match <>) '(1 2 3 4))))))
+ (if match
+ (map (cut match:substring match <>) '(1 2 3 4))
+ (error "Invalid SubRip timestamp: " s))))))
(define parse-time-span
- (let ((regexp (make-regexp "([0-9:,]+) --> ([0-9:,]+)")))
+ (let ((regexp (make-regexp "^([0-9:,]+) --> ([0-9:,]+)$")))
(lambda (s)
"Parse the SubRip formatted time span in the string S and return
two values: the start time and the end time. Valid input looks like
'00:00:03.417 --> 00:00:04.936'."
(let ((match (regexp-exec regexp s)))
- (values (parse-time (match:substring match 1))
- (parse-time (match:substring match 2)))))))
+ (if match
+ (values (parse-time (match:substring match 1))
+ (parse-time (match:substring match 2)))
+ (error "Invalid SubRip time range: " s))))))
(define (read-subrip port)
"Read a SubRip formatted subtitle from PORT."