>From 2526692ad80b78538cd37043bf20db2407b7a150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Thu, 21 Dec 2017 14:16:14 +0100 Subject: [PATCH 1/2] serve: Fix 'file-extension' so that the right MIME type is chosen. Reported by sirgazil at . * haunt/serve/mime-types.scm (%file-ext-regexp): Remove. (file-extension): Rewrite using 'string-rindex'. --- haunt/serve/mime-types.scm | 14 ++++---------- 1 file 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." -- 2.15.1