From ee62c48da969f1bcfefb2c2eee448c2b403859e1 Mon Sep 17 00:00:00 2001 From: Thomas Hochstein Date: Wed, 25 Mar 2020 21:46:05 +0100 Subject: [PATCH] Truncate extension of media items to 5 chars. That's the max length of the extensin database field. Fixes #609. Signed-off-by: Thomas Hochstein --- docs/NEWS | 2 ++ include/functions_images.inc.php | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/docs/NEWS b/docs/NEWS index ecf052459..be3cc2a59 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -1,6 +1,8 @@ Version 2.3.5-beta1 () ------------------------------------------------------------------------ + * Fix: Truncate extension of media items to 5 chars (which ist the + max length of the corresponding database field). Version 2.3.4 (March 25th, 2020) ------------------------------------------------------------------------ diff --git a/include/functions_images.inc.php b/include/functions_images.inc.php index 006ca698c..8b59552fb 100644 --- a/include/functions_images.inc.php +++ b/include/functions_images.inc.php @@ -2040,6 +2040,13 @@ function serendipity_uploadSecure($var, $strip_paths = true, $append_slash = fal } } + # truncate extensions to 5 chars + # 1) (\.[^.]{0,5}+) five chars after a dot are captured (possessively) + # 2) expression matches only if followed by anything that is no dot + # and has no / or \ at the end + # 3) if epxression matches, everything after the capture group is deleted + $var = preg_replace('@(\.[^.]{0,5}+)[^./\\\]*[^/\\\]{1,1}?$@', '$1', $var); + return $var; }