From 3a9009492e6d05fe657e3aacf34cf40ca3495db5 Mon Sep 17 00:00:00 2001 From: shadlaws Date: Fri, 18 Jan 2013 20:06:05 +0100 Subject: #1943 - Make legal_file::change_extension more robust. Previously would fail with dots in the directory but no extension. Added unit tests to verify the new change works. --- modules/gallery/helpers/legal_file.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'modules/gallery/helpers') diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php index e6f4cb54..e24aca36 100644 --- a/modules/gallery/helpers/legal_file.php +++ b/modules/gallery/helpers/legal_file.php @@ -137,15 +137,12 @@ class legal_file_Core { } /** - * Convert the extension of a filename. If the original filename has no + * Change the extension of a filename. If the original filename has no * extension, add the new one to the end. */ static function change_extension($filename, $new_ext) { - if (strpos($filename, ".") === false) { - return "{$filename}.{$new_ext}"; - } else { - return preg_replace("/\.[^\.]*?$/", ".{$new_ext}", $filename); - } + $filename_no_ext = preg_replace("/\.[^\.\/]*?$/", "", $filename); + return "{$filename_no_ext}.{$new_ext}"; } /** -- cgit v1.2.3