зеркало из https://github.com/mozilla/gecko-dev.git
another patch for bug 109179 "replace nsStdEscape with nsEscapeURLPart"
r=dougt,gagan sr=alecf,waterson
This commit is contained in:
Родитель
f075e3a0f4
Коммит
dfd95c7778
|
@ -20,6 +20,8 @@
|
|||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alec Flett <alecf@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
@ -35,13 +37,14 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/* Mac-specific local file url parsing */
|
||||
#include "nsIOService.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsPrintfCString.h"
|
||||
|
||||
static void SwapSlashColon(char * s)
|
||||
static void SwapSlashColon(char *s)
|
||||
{
|
||||
while (*s){
|
||||
while (*s) {
|
||||
if (*s == '/')
|
||||
*s++ = ':';
|
||||
else if (*s == ':')
|
||||
|
@ -51,7 +54,7 @@ static void SwapSlashColon(char * s)
|
|||
}
|
||||
}
|
||||
|
||||
static void PascalStringCopy(Str255 dst, const char* src)
|
||||
static void PascalStringCopy(Str255 dst, const char *src)
|
||||
{
|
||||
int srcLength = strlen(src);
|
||||
NS_ASSERTION(srcLength <= 255, "Oops, Str255 can't hold >255 chars");
|
||||
|
@ -62,102 +65,98 @@ static void PascalStringCopy(Str255 dst, const char* src)
|
|||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsIOService::GetURLSpecFromFile(nsIFile* aFile, char * *aURL)
|
||||
NS_IMETHODIMP
|
||||
nsIOService::GetURLSpecFromFile(nsIFile *aFile, char **aURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURL);
|
||||
*aURL = nsnull;
|
||||
NS_ENSURE_ARG_POINTER(aURL);
|
||||
*aURL = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
char* ePath = nsnull;
|
||||
nsCAutoString escPath;
|
||||
|
||||
rv = aFile->GetPath(&ePath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
SwapSlashColon(ePath);
|
||||
|
||||
// Escape the path with the directory mask
|
||||
rv = nsStdEscape(ePath, esc_Directory+esc_Forced, escPath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsresult rv;
|
||||
nsXPIDLCString ePath;
|
||||
|
||||
if (escPath[escPath.Length() - 1] != '/') {
|
||||
rv = aFile->GetPath(getter_Copies(ePath));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRBool dir;
|
||||
rv = aFile->IsDirectory(&dir);
|
||||
SwapSlashColon((char *) ePath.get());
|
||||
|
||||
nsCAutoString escPath;
|
||||
NS_NAMED_LITERAL_CSTRING(prefix, "file:///");
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
NS_WARNING(nsPrintfCString("Cannot tell if %s is a directory or file", escPath.get()).get());
|
||||
|
||||
if (NS_SUCCEEDED(rv) && dir)
|
||||
// make sure we have a trailing slash
|
||||
escPath += "/";
|
||||
}
|
||||
|
||||
escPath.Insert("file:///", 0);
|
||||
*aURL = ToNewCString(escPath);
|
||||
rv = *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
CRTFREEIF(ePath);
|
||||
return rv;
|
||||
// Escape the path with the directory mask
|
||||
if (NS_EscapeURLPart(ePath.get(), ePath.Length(), esc_Directory+esc_Forced, escPath))
|
||||
escPath.Insert(prefix, 0);
|
||||
else
|
||||
escPath.Assign(prefix + ePath);
|
||||
|
||||
// XXX this should be unnecessary
|
||||
if (escPath[escPath.Length() - 1] != '/') {
|
||||
PRBool dir;
|
||||
rv = aFile->IsDirectory(&dir);
|
||||
if (NS_FAILED(rv))
|
||||
NS_WARNING(nsPrintfCString("Cannot tell if %s is a directory or file", escPath.get()).get());
|
||||
else if (dir) {
|
||||
// make sure we have a trailing slash
|
||||
escPath += "/";
|
||||
}
|
||||
}
|
||||
|
||||
*aURL = ToNewCString(escPath);
|
||||
return *aURL ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsIOService::InitFileFromURLSpec(nsIFile* aFile, const char * aURL)
|
||||
NS_IMETHODIMP
|
||||
nsIOService::InitFileFromURLSpec(nsIFile *aFile, const char *aURL)
|
||||
{
|
||||
NS_ENSURE_ARG(aURL);
|
||||
nsresult rv;
|
||||
|
||||
nsXPIDLCString host, directory, fileBaseName, fileExtension;
|
||||
NS_ENSURE_ARG(aURL);
|
||||
nsresult rv;
|
||||
|
||||
nsXPIDLCString host, directory, fileBaseName, fileExtension;
|
||||
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(aFile, &rv);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Only nsILocalFile supported right now");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(aFile, &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("Only nsILocalFile supported right now");
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = ParseFileURL(aURL, getter_Copies(host), getter_Copies(directory),
|
||||
getter_Copies(fileBaseName), getter_Copies(fileExtension));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = ParseFileURL(aURL, getter_Copies(host),
|
||||
getter_Copies(directory),
|
||||
getter_Copies(fileBaseName),
|
||||
getter_Copies(fileExtension));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path;
|
||||
nsCAutoString component;
|
||||
nsCAutoString path;
|
||||
|
||||
if (host)
|
||||
{
|
||||
// We can end up with a host when given: file:// instead of file:///
|
||||
// Check to see if the host is a volume name - If so prepend it
|
||||
Str255 volName;
|
||||
FSSpec volSpec;
|
||||
if (host) {
|
||||
// We can end up with a host when given: file:// instead of file:///
|
||||
// Check to see if the host is a volume name - If so prepend it
|
||||
Str255 volName;
|
||||
FSSpec volSpec;
|
||||
|
||||
PascalStringCopy(volName, host);
|
||||
volName[++volName[0]] = ':';
|
||||
if (::FSMakeFSSpec(0, 0, volName, &volSpec) == noErr)
|
||||
path += host;
|
||||
}
|
||||
if (directory)
|
||||
{
|
||||
nsStdEscape(directory, esc_Directory, component);
|
||||
path += component;
|
||||
SwapSlashColon((char*)path.get());
|
||||
}
|
||||
if (fileBaseName)
|
||||
{
|
||||
nsStdEscape(fileBaseName, esc_FileBaseName, component);
|
||||
path += component;
|
||||
}
|
||||
if (fileExtension)
|
||||
{
|
||||
nsStdEscape(fileExtension, esc_FileExtension, component);
|
||||
path += '.';
|
||||
path += component;
|
||||
}
|
||||
|
||||
nsUnescape((char*)path.get());
|
||||
PascalStringCopy(volName, host);
|
||||
volName[++volName[0]] = ':';
|
||||
if (::FSMakeFSSpec(0, 0, volName, &volSpec) == noErr)
|
||||
path += host;
|
||||
}
|
||||
if (directory) {
|
||||
if (!NS_EscapeURLPart(directory.get(), directory.Length(), esc_Directory, path))
|
||||
path += directory;
|
||||
SwapSlashColon((char *) path.get());
|
||||
}
|
||||
if (fileBaseName) {
|
||||
if (!NS_EscapeURLPart(fileBaseName.get(), fileBaseName.Length(), esc_FileBaseName, path))
|
||||
path += fileBaseName;
|
||||
}
|
||||
if (fileExtension) {
|
||||
path += '.';
|
||||
if (!NS_EscapeURLPart(fileExtension.get(), fileExtension.Length(), esc_FileExtension, path))
|
||||
path += fileExtension;
|
||||
}
|
||||
|
||||
NS_UnescapeURL((char *) path.get());
|
||||
|
||||
// wack off leading :'s
|
||||
if (path.CharAt(0) == ':')
|
||||
path.Cut(0, 1);
|
||||
// wack off leading :'s
|
||||
if (path.CharAt(0) == ':')
|
||||
path.Cut(0, 1);
|
||||
|
||||
rv = localFile->InitWithPath(path.get());
|
||||
|
||||
return rv;
|
||||
|
||||
return localFile->InitWithPath(path.get());
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, char * *aURL)
|
|||
}
|
||||
|
||||
nsCAutoString escPath;
|
||||
NS_NAMED_LITERAL_CSTRING(prefix, "file://");
|
||||
NS_NAMED_LITERAL_CSTRING(prefix, "file:///");
|
||||
|
||||
// Escape the path with the directory mask
|
||||
if (NS_EscapeURLPart(ePath.get(), ePath.Length(), esc_Directory+esc_Forced, escPath))
|
||||
|
|
|
@ -68,7 +68,7 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, char * *aURL)
|
|||
}
|
||||
|
||||
nsCAutoString escPath;
|
||||
NS_NAMED_LITERAL_CSTRING(prefix, "file://");
|
||||
NS_NAMED_LITERAL_CSTRING(prefix, "file:///");
|
||||
|
||||
// Escape the path with the directory mask
|
||||
if (NS_EscapeURLPart(ePath.get(), ePath.Length(), esc_Directory+esc_Forced, escPath))
|
||||
|
|
Загрузка…
Ссылка в новой задаче