From f6519c6a83eae1d630c7101b868c8a36ea6ccb7c Mon Sep 17 00:00:00 2001 From: "pete%alphanumerica.com" Date: Fri, 3 Aug 2001 03:26:26 +0000 Subject: [PATCH] Fix for broken AppendRelativePath on unix. r=jag, sr=brendan b=55406. Note, this method will be going away soon. --pete git-svn-id: svn://10.0.0.236/trunk@100259 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/io/nsLocalFileUnix.cpp | 29 ++++++++-------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/mozilla/xpcom/io/nsLocalFileUnix.cpp b/mozilla/xpcom/io/nsLocalFileUnix.cpp index c4faae7a7d5..e47a4299ebf 100644 --- a/mozilla/xpcom/io/nsLocalFileUnix.cpp +++ b/mozilla/xpcom/io/nsLocalFileUnix.cpp @@ -55,6 +55,7 @@ #include "nsILocalFile.h" #include "nsEscape.h" #include "nsString.h" +#include "nsReadableUtils.h" #include "nsLocalFileUnix.h" #include "nsIComponentManager.h" #include "nsXPIDLString.h" @@ -431,33 +432,19 @@ nsLocalFile::AppendRelativePath(const char *fragment) CHECK_mPath(); NS_ENSURE_ARG(fragment); - // No leading '/' and no ".." component is allowed in the fragment. + if (*fragment == '\0') + return NS_OK; + + // No leading '/' if (*fragment == '/') return NS_ERROR_FILE_UNRECOGNIZED_PATH; - const char *dots = strstr(fragment, ".."); - if (dots && - (dots == fragment || dots[-1] == '/') && - (dots[2] == '\0' || dots[2] == '/')) { - // XXXbe what's the difference between UNRECOGNIZED and INVALID? - return NS_ERROR_FILE_UNRECOGNIZED_PATH; - } + mPath.Adopt(ToNewCString(mPath + NS_LITERAL_CSTRING("/") + + nsDependentCString(fragment))); - char *newPath = (char *)nsMemory::Alloc(strlen(mPath) + - strlen(fragment) + - 2); - if (!newPath) + if (!mPath.get()) return NS_ERROR_OUT_OF_MEMORY; - strcpy(newPath, mPath); - strcat(newPath, "/"); - strcat(newPath, fragment); - // strip trailing slashes that came from fragment - ssize_t len = strlen(newPath); - while (newPath[len-1] == '/' && len > 1) - newPath[--len] = '\0'; - - mPath.Adopt(newPath); InvalidateCache(); return NS_OK; }