From 58e7c5ec42cc75d195cf6797cb85c7fa14fb71a7 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Wed, 15 Jan 2014 10:39:31 +0000 Subject: [PATCH] preg_replace to remove full path prefix Use preg_replace to only replace the first instance on a full path to make it local Avoids str_replace replacing all instances in the string --- lib/multiple-results.php | 3 ++- lib/settings.php | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/multiple-results.php b/lib/multiple-results.php index 34f1b97..b5e8136 100644 --- a/lib/multiple-results.php +++ b/lib/multiple-results.php @@ -129,7 +129,8 @@ if (startTab!=top.ICEcoder.selectedTab) { if (strpos($f,$ICEcoder['bannedFiles'][$i])!==false) {$bFile = true;}; } // Exclude the folder ICEcoder is running from - $localPath = str_replace(str_replace("\\","/",$docRoot),"",$fullPath); + $rootPrefix = '/'.str_replace("/","\/",preg_quote(str_replace("\\","/",$docRoot))).'/'; + $localPath = preg_replace($rootPrefix, '', $fullPath, 1); if (strpos($localPath, $ICEcoderDir)===0) { $bFile = true; } diff --git a/lib/settings.php b/lib/settings.php index 7b764cc..0bfec94 100644 --- a/lib/settings.php +++ b/lib/settings.php @@ -79,7 +79,9 @@ if ($_SESSION['loggedIn']) { } // Establish the dir ICEcoders running from -$ICEcoderDir = rtrim(str_replace(str_replace("\\","/",$docRoot),"",str_replace("\\","/",dirname(__FILE__))),"/lib"); +$ICEcoderDirFullPath = rtrim(str_replace("\\","/",dirname(__FILE__)),"/lib"); +$rootPrefix = '/'.str_replace("/","\/",preg_quote(str_replace("\\","/",$docRoot))).'/'; +$ICEcoderDir = preg_replace($rootPrefix, '', $ICEcoderDirFullPath, 1); // Setup our file security vars $settingsArray = array("findFilesExclude","bannedFiles","allowedIPs");