Skip to content

Commit 704197e

Browse files
committed
Merge pull request #166 from arcfieldOSS/final
Bug Fixes in file writing and dir naming.
2 parents b2617f1 + 0f1a13b commit 704197e

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

phpfastcache/3.0.0/drivers/files.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function driver_set($keyword, $value = "", $time = 300, $option = array() ) {
9191
* because first-to-lock wins and the file will exist before the writer attempts
9292
* to write.
9393
*/
94-
if($toWrite == true && !@file_exists($tmp_path && !@file_exists($file_path))) {
94+
if($toWrite == true && !@file_exists($tmp_path) && !@file_exists($file_path)) {
9595
try {
9696
$f = @fopen($tmp_path, "c");
9797
if ($f) {

phpfastcache/3.0.0/phpfastcache.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,14 @@ public static function getPath($skip_create_path = false, $config) {
163163
if($securityKey == "" || $securityKey == "auto") {
164164
$securityKey = self::$config['securityKey'];
165165
if($securityKey == "auto" || $securityKey == "") {
166-
$securityKey = isset($_SERVER['HTTP_HOST']) ? ltrim(strtolower($_SERVER['HTTP_HOST']),"www.") : "default";
167-
$securityKey = preg_replace("/[^a-zA-Z0-9]+/","",$securityKey);
166+
$securityKey = isset($_SERVER['HTTP_HOST']) ? preg_replace('/^www./','',strtolower($_SERVER['HTTP_HOST'])) : "default";
168167
}
169168
}
170169
if($securityKey != "") {
171170
$securityKey.= "/";
172171
}
172+
173+
$securityKey = self::cleanFileName($securityKey);
173174

174175
$full_path = $path."/".$securityKey;
175176
$full_pathx = md5($full_path);
@@ -199,6 +200,12 @@ public static function getPath($skip_create_path = false, $config) {
199200
return realpath($full_path);
200201

201202
}
203+
204+
public static function cleanFileName($filename) {
205+
$regex = ['/[\?\[\]\/\\\=\<\>\:\;\,\'\"\&\$\#\*\(\)\|\~\`\!\{\}]/','/\.$/','/^\./'];
206+
$replace = ['-','',''];
207+
return preg_replace($regex,$replace,$filename);
208+
}
202209

203210

204211
public static function __setChmodAuto($config) {

0 commit comments

Comments
 (0)