From dd04acdb59bbbbddf1943e78d21e6848784a9424 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 31 Oct 2016 10:14:25 +0100 Subject: [PATCH] Fixes #80 --- DataStorage/Cache/FileCache.php | 10 +++++----- System/File/ContainerInterface.php | 3 ++- System/File/Local/Directory.php | 4 ++-- System/File/Local/File.php | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/DataStorage/Cache/FileCache.php b/DataStorage/Cache/FileCache.php index f1afed11e..67efe4ac1 100644 --- a/DataStorage/Cache/FileCache.php +++ b/DataStorage/Cache/FileCache.php @@ -142,7 +142,7 @@ class FileCache implements CacheInterface return false; } - $path = File::sanitize($key); + $path = File::sanitize($key, '~'); file_put_contents($this->cachePath . '/' . $path, $this->build($value, $expire)); @@ -158,7 +158,7 @@ class FileCache implements CacheInterface return false; } - $path = File::sanitize($key); + $path = File::sanitize($key, '~'); if (!file_exists($this->cachePath . '/' . $path)) { file_put_contents($this->cachePath . '/' . $path, $this->build($value, $expire)); @@ -274,7 +274,7 @@ class FileCache implements CacheInterface return null; } - $name = File::sanitize($key); + $name = File::sanitize($key, '~'); $path = $this->cachePath . '/' . $name; if(!file_exists($path)) { @@ -341,7 +341,7 @@ class FileCache implements CacheInterface return false; } - $name = File::sanitize($key); + $name = File::sanitize($key, '~'); $path = $this->cachePath . '/' . $name; if ($expire < 0 && file_exists($path)) { @@ -404,7 +404,7 @@ class FileCache implements CacheInterface return false; } - $path = File::sanitize($key); + $path = File::sanitize($key, '~'); if (file_exists($this->cachePath . '/' . $path)) { file_put_contents($this->cachePath . '/' . $path, $this->build($value, $expire)); diff --git a/System/File/ContainerInterface.php b/System/File/ContainerInterface.php index 640665651..a95e9da62 100644 --- a/System/File/ContainerInterface.php +++ b/System/File/ContainerInterface.php @@ -197,13 +197,14 @@ interface ContainerInterface * Make name/path operating system safe. * * @param string $path Path of the resource + * @param string $replace Replace invalid chars with * * @return string * * @since 1.0.0 * @author Dennis Eichhorn */ - public static function sanitize(string $path) : string; + public static function sanitize(string $path, string $replace = '') : string; /** * Get amount of sub-resources. diff --git a/System/File/Local/Directory.php b/System/File/Local/Directory.php index c39db39ca..65d116a8d 100644 --- a/System/File/Local/Directory.php +++ b/System/File/Local/Directory.php @@ -260,9 +260,9 @@ class Directory extends FileAbstract implements DirectoryInterface /** * {@inheritdoc} */ - public static function sanitize(string $path) : string + public static function sanitize(string $path, string $replace = '') : string { - return preg_replace('[^\w\s\d\.\-_~,;:\[\]\(\]\/]', '', $path); + return preg_replace('[^\w\s\d\.\-_~,;:\[\]\(\]\/]', $replace, $path); } /** diff --git a/System/File/Local/File.php b/System/File/Local/File.php index a4aaa6088..62d0199fa 100644 --- a/System/File/Local/File.php +++ b/System/File/Local/File.php @@ -143,9 +143,9 @@ class File extends FileAbstract implements FileInterface /** * {@inheritdoc} */ - public static function sanitize(string $path) : string + public static function sanitize(string $path, string $replace = '') : string { - return preg_replace('/[^\w\s\d\.\-_~,;\[\]\(\]]/', '', $path); + return preg_replace('/[^\w\s\d\.\-_~,;\[\]\(\]]/', $replace, $path); } /**