]> git.mxchange.org Git - friendica.git/commitdiff
Add Strings::sanitizeFilePathItem method
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 1 Apr 2019 01:39:19 +0000 (21:39 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 1 Apr 2019 01:39:19 +0000 (21:39 -0400)
src/Util/Strings.php

index d6583b9c61c0eb29993ee350d2eb2683e3592c3a..b2b710d96f2c59ca86e9a545bb342b88849868d7 100644 (file)
@@ -375,4 +375,20 @@ class Strings
   )*
 )@';
        }
+
+       /**
+        * Ensures a single path item doesn't contain any path-traversing characters
+        *
+        * @see https://stackoverflow.com/a/46097713
+        * @param string $pathItem
+        * @return string
+        */
+       public static function sanitizeFilePathItem($pathItem)
+       {
+               $pathItem = str_replace('/', '_', $pathItem);
+               $pathItem = str_replace('\\', '_', $pathItem);
+               $pathItem = str_replace(DIRECTORY_SEPARATOR, '_', $pathItem); // In case it does not equal the standard values
+
+               return $pathItem;
+       }
 }