From 4221ef34bac8bd2eb848e2bf7690934b2fb2a8ce Mon Sep 17 00:00:00 2001 From: xevidos Date: Wed, 11 Dec 2019 11:23:33 -0500 Subject: [PATCH] Updated regex pull to use constant, set default of file list result to empty array --- components/filemanager/class.filemanager.php | 2 ++ components/filemanager/init.js | 2 +- components/install/install.php | 6 ++++-- components/project/class.project.php | 8 ++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/components/filemanager/class.filemanager.php b/components/filemanager/class.filemanager.php index 2155d9c..a3175a8 100755 --- a/components/filemanager/class.filemanager.php +++ b/components/filemanager/class.filemanager.php @@ -12,6 +12,8 @@ require_once('./class.archive.php'); class Filemanager extends Common { + const PATH_REGEX = '/[^\w\-\._@]/'; + ////////////////////////////////////////////////////////////////// // PROPERTIES ////////////////////////////////////////////////////////////////// diff --git a/components/filemanager/init.js b/components/filemanager/init.js index 870bb40..56807c8 100755 --- a/components/filemanager/init.js +++ b/components/filemanager/init.js @@ -602,7 +602,7 @@ let data = await _this.get_indexes( path ); let response = codiad.jsend.parse( data ); - let result = null; + let result = []; if( response != 'error' ) { diff --git a/components/install/install.php b/components/install/install.php index 07ea2a1..8557f70 100644 --- a/components/install/install.php +++ b/components/install/install.php @@ -5,6 +5,8 @@ require_once( __DIR__ . "/../settings/class.settings.php" ); class Install { + const PATH_REGEX = '/[^\w\-\._@]/'; + public $active = ""; public $config = ""; public $db_types = array(); @@ -84,7 +86,7 @@ class Install { function clean_username( $username ) { - return strtolower( preg_replace( '/[^\w\-\._@]/', '-', $username ) ); + return strtolower( preg_replace( self::PATH_REGEX, '-', $username ) ); } function create_config() { @@ -157,7 +159,7 @@ define("WSURL", BASE_URL . "/workspace"); if ( ! $this->is_abs_path( $project_path ) ) { - $project_path = preg_replace( '/[^\w\-._@]/', '-', $project_path ); + $project_path = preg_replace( self::PATH_REGEX, '-', $project_path ); $project_path = $this->username . "/" . $project_path; if( ! is_dir( $this->workspace . "/" . $project_path ) ) { diff --git a/components/project/class.project.php b/components/project/class.project.php index 5fdbd24..652eaea 100755 --- a/components/project/class.project.php +++ b/components/project/class.project.php @@ -414,7 +414,7 @@ class Project extends Common { } if ( $path != '' ) { - $user_path = WORKSPACE . '/' . preg_replace( '/[^\w-]/', '', strtolower( $_SESSION["user"] ) ); + $user_path = WORKSPACE . '/' . preg_replace( Filemanager::PATH_REGEX, '', strtolower( $_SESSION["user"] ) ); if( ! $this->isAbsPath( $path ) ) { @@ -433,7 +433,7 @@ class Project extends Common { if( ! is_dir( WORKSPACE . '/' . $path ) ) { - mkdir( WORKSPACE . '/' . $path ); + mkdir( WORKSPACE . '/' . $path, 0755, true ); } } else { @@ -576,13 +576,13 @@ class Project extends Common { public function SanitizePath() { $sanitized = str_replace( " ", "_", $this->path ); - return preg_replace( '/[^\w-]/', '', strtolower( $sanitized ) ); + return preg_replace( Filemanager::PATH_REGEX, '', strtolower( $sanitized ) ); } public function sanitize_path( $path ) { $sanitized = str_replace( " ", "_", $path ); - return preg_replace( '/[^\w-]/', '', strtolower( $sanitized ) ); + return preg_replace( Filemanager::PATH_REGEX, '', strtolower( $sanitized ) ); } //////////////////////////////////////////////////////////////////