From 3900791a0f747aa42e017152cdca67127d9f8133 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 19 Dec 2024 13:08:25 -0800 Subject: [PATCH] T.P.MIME: fix `extensionFromMimeType`. We had a few special cases encoded, but as previously written they wouldn't work properly with modifiers like `;charset=utf-8`. --- src/Text/Pandoc/MIME.hs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Text/Pandoc/MIME.hs b/src/Text/Pandoc/MIME.hs index b6aae1092..9104f36b3 100644 --- a/src/Text/Pandoc/MIME.hs +++ b/src/Text/Pandoc/MIME.hs @@ -45,20 +45,21 @@ getMimeTypeDef :: FilePath -> MimeType getMimeTypeDef = fromMaybe "application/octet-stream" . getMimeType extensionFromMimeType :: MimeType -> Maybe T.Text --- few special cases, where there are multiple options: -extensionFromMimeType "text/plain" = Just "txt" -extensionFromMimeType "video/quicktime" = Just "mov" -extensionFromMimeType "video/mpeg" = Just "mpeg" -extensionFromMimeType "video/dv" = Just "dv" -extensionFromMimeType "image/vnd.djvu" = Just "djvu" -extensionFromMimeType "image/tiff" = Just "tiff" -extensionFromMimeType "image/jpeg" = Just "jpg" -extensionFromMimeType "application/xml" = Just "xml" -extensionFromMimeType "application/ogg" = Just "ogg" -extensionFromMimeType "image/svg+xml" = Just "svg" -- avoid svgz extensionFromMimeType mimetype = - M.lookup (T.takeWhile (/=';') mimetype) reverseMimeTypes -- note: we just look up the basic mime type, dropping the content-encoding etc. + case T.takeWhile (/=';') mimetype of + -- handle a few special cases, where there are multiple options: + "text/plain" -> Just "txt" + "video/quicktime" -> Just "mov" + "video/mpeg" -> Just "mpeg" + "video/dv" -> Just "dv" + "image/vnd.djvu" -> Just "djvu" + "image/tiff" -> Just "tiff" + "image/jpeg" -> Just "jpg" + "application/xml" -> Just "xml" + "application/ogg" -> Just "ogg" + "image/svg+xml" -> Just "svg" -- avoid svgz + mt -> M.lookup mt reverseMimeTypes -- | Determine general media category for file path, e.g. --