Simplify filetype matching regexes
authorBernie Innocenti <bernie@codewiz.org>
Sat, 2 May 2009 09:21:24 +0000 (11:21 +0200)
committerBernie Innocenti <bernie@codewiz.org>
Sat, 2 May 2009 09:21:24 +0000 (11:21 +0200)
geekigeeki.py

index 470752de0d44076f31272693a206bf0a1ed9cdc2..a36eced13ff809056a7aae93d66ef79e4fbd32ed 100755 (executable)
@@ -27,10 +27,11 @@ title_done = False
 import cgi, sys, os, re, errno, stat
 
 # FIXME: we accept stuff like foo/../bar and we shouldn't
-file_re = re.compile(r"^\b([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)\b$")
-img_re = re.compile(r"^.*\.(png|gif|jpg|jpeg|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", re.IGNORECASE)
-video_re = re.compile(r"^.*\.(ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", re.IGNORECASE)
-url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$")
+file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)")
+video_ext = "ogg|ogv|oga" # Not supported by Firefox 3.5: mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt
+img_re = re.compile(r".*\.(png|gif|jpg|jpeg|bmp|ico|" +  video_ext + ")", re.IGNORECASE)
+video_re = re.compile(r".*\.(" + video_ext + ")", re.IGNORECASE)
+url_re = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S")
 ext_re = re.compile(r"\.([^\./]+)$")
 
 # CGI stuff ---------------------------------------------------------