From 529f7198b1721ba0a9cc5fa2ddf7267674faa070 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Tue, 24 Jul 2012 13:41:08 +0100 Subject: [PATCH] replace indexOf with lastIndex on shortURLstarts causes probs if you have the same term more than once in your path (ie, var/www/mysite/www), previously took first www Now takes last one and solves path issues in quite a few areas --- index.php | 2 +- lib/coder.js | 12 ++++++------ lib/file-control.php | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/index.php b/index.php index 0528c86..874b576 100644 --- a/index.php +++ b/index.php @@ -89,7 +89,7 @@ previousFiles = [Delete Rename - View Webpage + View Webpage Zip It! Properties diff --git a/lib/coder.js b/lib/coder.js index 0318e9f..54610c6 100644 --- a/lib/coder.js +++ b/lib/coder.js @@ -650,7 +650,7 @@ var ICEcoder = { } } else if (top.ICEcoder.thisFileFolderLink) { // We clicked a file/folder. Work out a shortened URL for the file, with pipes instead of slashes - shortURL = top.ICEcoder.thisFileFolderLink.substr((top.ICEcoder.thisFileFolderLink.indexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.thisFileFolderLink.length).replace(/\//g,"|"); + shortURL = top.ICEcoder.thisFileFolderLink.substr((top.ICEcoder.thisFileFolderLink.lastIndexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.thisFileFolderLink.length).replace(/\//g,"|"); // If we have the CTRL key down if (top.ICEcoder.ctrlKeyDown) { @@ -731,7 +731,7 @@ var ICEcoder = { newFolder: function() { var newFolder, shortURL; - shortURL = top.ICEcoder.rightClickedFile.substr((top.ICEcoder.rightClickedFile.indexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.rightClickedFile.length).replace(/\|/g,"/"); + shortURL = top.ICEcoder.rightClickedFile.substr((top.ICEcoder.rightClickedFile.lastIndexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.rightClickedFile.length).replace(/\|/g,"/"); newFolder = top.ICEcoder.getInput('Enter New Folder Name at '+shortURL+'/',''); if (newFolder) { newFolder = shortURL + "/" + newFolder; @@ -751,7 +751,7 @@ var ICEcoder = { // work out a shortened URL for the file shortURL = top.ICEcoder.thisFileFolderLink.replace(/\|/g,"/"); - shortURL = shortURL.substr((shortURL.indexOf(shortURLStarts)+shortURLStarts.length),shortURL.length); + shortURL = shortURL.substr((shortURL.lastIndexOf(shortURLStarts)+shortURLStarts.length),shortURL.length); // No reason why we can't open a file (so far) canOpenFile = true; @@ -804,10 +804,10 @@ var ICEcoder = { var shortURL; if (!oldName) { - shortURL = top.ICEcoder.rightClickedFile.substr((top.ICEcoder.rightClickedFile.indexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.rightClickedFile.length).replace(/\|/g,"/"); + shortURL = top.ICEcoder.rightClickedFile.substr((top.ICEcoder.rightClickedFile.lastIndexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.rightClickedFile.length).replace(/\|/g,"/"); oldName = top.ICEcoder.rightClickedFile.replace(/\|/g,"/"); } else { - shortURL = oldName.substr((oldName.indexOf(shortURLStarts)+top.shortURLStarts.length),oldName.length).replace(/\|/g,"/"); + shortURL = oldName.substr((oldName.lastIndexOf(shortURLStarts)+top.shortURLStarts.length),oldName.length).replace(/\|/g,"/"); } if (!newName) { newName = top.ICEcoder.getInput('Please enter the new name for',shortURL); @@ -1241,7 +1241,7 @@ var ICEcoder = { // Chmod on files if (action=="chmod") { // Identify a shortened URL for our file and get our target element based on this - shortURL = top.ICEcoder.rightClickedFile.substr((top.ICEcoder.rightClickedFile.indexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.rightClickedFile.length).replace(/\|/g,"/"); + shortURL = top.ICEcoder.rightClickedFile.substr((top.ICEcoder.rightClickedFile.lastIndexOf(shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.rightClickedFile.length).replace(/\|/g,"/"); targetElem = document.getElementById('filesFrame').contentWindow.document.getElementById(shortURL.replace(/\//g,"|")+"_perms"); // Set the new perms targetElem.innerHTML = perms; diff --git a/lib/file-control.php b/lib/file-control.php index f3ae44d..f3c4f5c 100644 --- a/lib/file-control.php +++ b/lib/file-control.php @@ -30,7 +30,7 @@ if ($_GET['action']=="load") { if ($_SESSION['userLevel'] == 10 || ($_SESSION['userLevel'] < 10 && $bannedFile==false)) { echo ''; + echo 'top.ICEcoder.shortURL = shortURL.substr((shortURL.lastIndexOf(top.shortURLStarts)+top.shortURLStarts.length),shortURL.length);'; $loadedFile = file_get_contents($file); echo '","",$loadedFile).''; } else { @@ -268,7 +268,7 @@ if (action=="save") { if ($file=="|[NEW]"||$saveType=="saveAs") { ?> if (top.ICEcoder.rightClickedFile) { - shortURL = top.ICEcoder.rightClickedFile.substr((top.ICEcoder.rightClickedFile.indexOf(top.shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.rightClickedFile.length).replace(/\|/g,"/")+"/"; + shortURL = top.ICEcoder.rightClickedFile.substr((top.ICEcoder.rightClickedFile.lastIndexOf(top.shortURLStarts)+top.shortURLStarts.length),top.ICEcoder.rightClickedFile.length).replace(/\|/g,"/")+"/"; newFileName = top.ICEcoder.getInput('Enter Filename',shortURL); } else { newFileName = top.ICEcoder.getInput('Enter Filename','/');