diff --git a/inc/confutils.php b/inc/confutils.php
index e3805d74ec4d61a6e39261dd82c9302a7408580b..c587bed4d74e1de4906fba00e5bd17f940708d18 100644
--- a/inc/confutils.php
+++ b/inc/confutils.php
@@ -365,12 +365,12 @@ function conf_decodeString($str) {
 function array_merge_with_removal($current, $new) {
     foreach ($new as $val) {
         if (substr($val,0,1) == '!') {
-            $idx = array_search(substr($val,1),$current);
+            $idx = array_search(trim(substr($val,1)),$current);
             if ($idx !== false) {
                 unset($current[$idx]);
             }
         } else {
-            $current[] = $val;
+            $current[] = trim($val);
         }
     }