summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-12-21 14:16:14 +0100
committerDavid Thompson <dthompson@vistahigherlearning.com>2017-12-21 08:51:02 -0500
commite7b1b290b11c4f2c89999fc079278e917f65bca9 (patch)
treeb41942a69a67e9f8c4d9005eb6329fa5186a57e5
parent4bf24d36f6faf09cdf8eccb05ad9bd7dda81393f (diff)
serve: Fix 'file-extension' so that the right MIME type is chosen.
Reported by sirgazil at <https://lists.gnu.org/archive/html/guile-user/2017-12/msg00070.html>. * haunt/serve/mime-types.scm (%file-ext-regexp): Remove. (file-extension): Rewrite using 'string-rindex'.
-rw-r--r--haunt/serve/mime-types.scm14
1 files changed, 4 insertions, 10 deletions
diff --git a/haunt/serve/mime-types.scm b/haunt/serve/mime-types.scm
index 4c9c0f1..c625dd5 100644
--- a/haunt/serve/mime-types.scm
+++ b/haunt/serve/mime-types.scm
@@ -539,16 +539,10 @@
("vrml" . x-world/x-vrml)
("wrl" . x-world/x-vrml))))
-(define %file-ext-regexp
- (make-regexp "(\\.(.*)|[~%])$"))
-
-(define (file-extension file-name)
- "Return the file extension for FILE-NAME, or #f if one is not
-found."
- (and=> (regexp-exec %file-ext-regexp file-name)
- (lambda (match)
- (or (match:substring match 2)
- (match:substring match 1)))))
+(define (file-extension file)
+ "Return the extension of FILE or #f if there is none."
+ (let ((dot (string-rindex file #\.)))
+ (and dot (substring file (+ 1 dot) (string-length file)))))
(define (mime-type file-name)
"Guess the MIME type for FILE-NAME based upon its file extension."