From 0e20e00c8d53433507f178098c17d152d754de78 Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Mon, 15 Apr 2019 17:34:42 +0200 Subject: [Minor] mime_types: decode hex encoded characters in filenames to improve file extension detection --- src/plugins/lua/mime_types.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/plugins/lua/mime_types.lua b/src/plugins/lua/mime_types.lua index c898540c0..1141047a2 100644 --- a/src/plugins/lua/mime_types.lua +++ b/src/plugins/lua/mime_types.lua @@ -851,6 +851,9 @@ local function check_mime_type(task) fname:sub(1, ch_pos))) end + -- Decode hex encoded characters + fname = string.gsub(fname, '%%(%x%x)', function (hex) return string.char(tonumber(hex,16)) end ) + -- Replace potentially bad characters with '?' fname = fname:gsub('[^%s%g]', '?') -- cgit v1.2.3 From 0165255b168b4a55056f533f9c761b36cceb29b6 Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Tue, 16 Apr 2019 09:25:14 +0200 Subject: [Minor] mime_types: use higher weighted MIME type if detected MIME type differs from Content-Type header --- src/plugins/lua/mime_types.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/plugins/lua/mime_types.lua b/src/plugins/lua/mime_types.lua index 1141047a2..e621b5666 100644 --- a/src/plugins/lua/mime_types.lua +++ b/src/plugins/lua/mime_types.lua @@ -1086,13 +1086,12 @@ local function check_mime_type(task) end if map then - local v + local v = map:get_key(ct) local detected_different = false if detected_ct and detected_ct ~= ct then - v = map:get_key(detected_ct) + local v_detected = map:get_key(detected_ct) + if v_detected > v then v = v_detected end detected_different = true - else - v = map:get_key(ct) end if v then local n = tonumber(v) -- cgit v1.2.3