From 4e08744631471a26ea490cbc1e2025415a87ff19 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Fri, 17 Feb 2023 16:10:59 +0100 Subject: [PATCH] addDirSep() can check for arbitrary chars at end of string --- inc/inc.Utils.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/inc/inc.Utils.php b/inc/inc.Utils.php index 25d3a0ecb..ace755d68 100644 --- a/inc/inc.Utils.php +++ b/inc/inc.Utils.php @@ -663,16 +663,19 @@ function get_extension($mimetype) { /* {{{ */ } /* }}} */ /** - * Adds a missing front slash to a string + * Adds a missing directory separator (or any other char) to a string * * This function is used for making sure a directory name has a - * trailing directory separator + * trailing directory separator. It can also be used to add + * any other char at the end of a string, e.g. an URL which must + * end in '/' (DIRECTORY_SEPARATOR wouldn't be right in that case, + * because it is '\' on Windows) */ -function addDirSep($str) { /* {{{ */ +function addDirSep($str, $chr=DIRECTORY_SEPARATOR) { /* {{{ */ if(trim($str) == '') return ''; - if(substr(trim($str), -1, 1) != DIRECTORY_SEPARATOR) - return trim($str).DIRECTORY_SEPARATOR; + if(substr(trim($str), -1, 1) != $chr) + return trim($str).$chr; else return trim($str); } /* }}} */