зеркало из https://github.com/mozilla/pjs.git
Fixes for bugs #3779,#2784. Member initialization of nsFileURL for windows compiler, escaping of url when made from path or spec, add file:// on macintosh when making a url from a spec. [bugs introduced when, for dp, I changed nsFilePath not to escape]. a=chofmann.
This commit is contained in:
Родитель
d7b5d09fd7
Коммит
296a662cd4
|
@ -255,7 +255,7 @@ class NS_BASE nsFileSpec
|
|||
long parID,
|
||||
ConstStr255Param name);
|
||||
nsFileSpec(const FSSpec& inSpec)
|
||||
: mSpec(inSpec), mError(NS_OK) {}
|
||||
: mSpec(inSpec), mError(NS_OK), mPath(nsnull) {}
|
||||
void operator = (const FSSpec& inSpec)
|
||||
{ mSpec = inSpec; mError = NS_OK; }
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "FullPath.h"
|
||||
#include "FileCopy.h"
|
||||
#include "MoreFilesExtras.h"
|
||||
#include "nsEscape.h"
|
||||
|
||||
#include <Aliases.h>
|
||||
#include <Folders.h>
|
||||
|
@ -917,7 +916,7 @@ nsFilePath::nsFilePath(const char* inString, PRBool inCreateDirs)
|
|||
, mFileSpec(inString, inCreateDirs)
|
||||
{
|
||||
// Make canonical and absolute.
|
||||
char * path = MacFileHelpers::PathNameFromFSSpec( mFileSpec, TRUE );
|
||||
char * path = MacFileHelpers::PathNameFromFSSpec( mFileSpec, true );
|
||||
mPath = MacFileHelpers::EncodeMacPath(path, true, false);
|
||||
}
|
||||
|
||||
|
@ -928,7 +927,7 @@ nsFilePath::nsFilePath(const nsString& inString, PRBool inCreateDirs)
|
|||
, mFileSpec(nsAutoCString(inString), inCreateDirs)
|
||||
{
|
||||
// Make canonical and absolute.
|
||||
char * path = MacFileHelpers::PathNameFromFSSpec( mFileSpec, TRUE );
|
||||
char * path = MacFileHelpers::PathNameFromFSSpec( mFileSpec, true );
|
||||
mPath = MacFileHelpers::EncodeMacPath(path, true, false);
|
||||
}
|
||||
|
||||
|
@ -952,7 +951,7 @@ nsFilePath::nsFilePath(const nsFileURL& inOther)
|
|||
void nsFilePath::operator = (const nsFileSpec& inSpec)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char * path = MacFileHelpers::PathNameFromFSSpec( inSpec.mSpec, TRUE );
|
||||
char * path = MacFileHelpers::PathNameFromFSSpec( inSpec.mSpec, true );
|
||||
delete [] mPath;
|
||||
mPath = MacFileHelpers::EncodeMacPath(path, true, false);
|
||||
mFileSpec = inSpec;
|
||||
|
@ -1032,8 +1031,17 @@ void nsFileURL::operator = (const nsFileSpec& inOther)
|
|||
{
|
||||
mFileSpec = inOther;
|
||||
delete [] mURL;
|
||||
char* path = MacFileHelpers::PathNameFromFSSpec( mFileSpec, TRUE );
|
||||
mURL = MacFileHelpers::EncodeMacPath(path, true, true);
|
||||
char* path = MacFileHelpers::PathNameFromFSSpec( mFileSpec, true );
|
||||
char* encodedPath = MacFileHelpers::EncodeMacPath(path, true, true);
|
||||
char* encodedURL = nsFileSpecHelpers::AllocCat(kFileURLPrefix, encodedPath);
|
||||
delete [] encodedPath;
|
||||
if (encodedURL[strlen(encodedURL) - 1] != '/' && inOther.IsDirectory())
|
||||
{
|
||||
mURL = nsFileSpecHelpers::AllocCat(encodedURL, "/");
|
||||
delete [] encodedURL;
|
||||
}
|
||||
else
|
||||
mURL = encodedURL;
|
||||
} // nsFileURL::operator =
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
|
|
@ -62,45 +62,64 @@ NS_BASE char* nsEscape(const char * str, nsEscapeMask mask)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE char* nsEscapeCount(const char * str, PRInt32 len, nsEscapeMask mask, PRInt32 * out_len)
|
||||
NS_BASE char* nsEscapeCount(
|
||||
const char * str,
|
||||
PRInt32 len,
|
||||
nsEscapeMask mask,
|
||||
PRInt32* out_len)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
int32 i, extra = 0;
|
||||
char *hexChars = "0123456789ABCDEF";
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
if(!str)
|
||||
return(0);
|
||||
int i, extra = 0;
|
||||
char* hexChars = "0123456789ABCDEF";
|
||||
|
||||
register const unsigned char* src = (unsigned char *) str;
|
||||
register const unsigned char* src = (const unsigned char *) str;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (!IS_OK(src[i]))
|
||||
extra+=2; /* the escape, plus an extra byte for each nibble */
|
||||
}
|
||||
{
|
||||
if (!IS_OK(*src++))
|
||||
extra += 2; /* the escape, plus an extra byte for each nibble */
|
||||
}
|
||||
|
||||
char* result = new char[len + extra + 1];
|
||||
if (!result)
|
||||
return(0);
|
||||
return 0;
|
||||
|
||||
register unsigned char* dst = (unsigned char *) result;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
unsigned char c = src[i];
|
||||
if (IS_OK(c))
|
||||
{
|
||||
*dst++ = c;
|
||||
}
|
||||
else if (mask == url_XPAlphas && c == ' ')
|
||||
{
|
||||
*dst++ = '+'; /* convert spaces to pluses */
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst++ = HEX_ESCAPE;
|
||||
*dst++ = hexChars[c >> 4]; /* high nibble */
|
||||
*dst++ = hexChars[c & 0x0f]; /* low nibble */
|
||||
}
|
||||
}
|
||||
src = (const unsigned char *) str;
|
||||
if (mask == url_XPAlphas)
|
||||
{
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
unsigned char c = *src++;
|
||||
if (IS_OK(c))
|
||||
*dst++ = c;
|
||||
else if (c == ' ')
|
||||
*dst++ = '+'; /* convert spaces to pluses */
|
||||
else
|
||||
{
|
||||
*dst++ = HEX_ESCAPE;
|
||||
*dst++ = hexChars[c >> 4]; /* high nibble */
|
||||
*dst++ = hexChars[c & 0x0f]; /* low nibble */
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
unsigned char c = *src++;
|
||||
if (IS_OK(c))
|
||||
*dst++ = c;
|
||||
else
|
||||
{
|
||||
*dst++ = HEX_ESCAPE;
|
||||
*dst++ = hexChars[c >> 4]; /* high nibble */
|
||||
*dst++ = hexChars[c & 0x0f]; /* low nibble */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*dst = '\0'; /* tack on eos */
|
||||
if(out_len)
|
||||
|
@ -125,27 +144,24 @@ NS_BASE PRInt32 nsUnescapeCount(char * str)
|
|||
|
||||
while (*src)
|
||||
if (*src != HEX_ESCAPE)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
src++; /* walk over escape */
|
||||
if (*src)
|
||||
{
|
||||
{
|
||||
*dst = UNHEX(*src) << 4;
|
||||
src++;
|
||||
}
|
||||
}
|
||||
if (*src)
|
||||
{
|
||||
{
|
||||
*dst = (*dst + UNHEX(*src));
|
||||
src++;
|
||||
}
|
||||
}
|
||||
dst++;
|
||||
}
|
||||
}
|
||||
|
||||
*dst = 0;
|
||||
|
||||
return (int)(dst - str);
|
||||
|
||||
} /* NET_UnEscapeCnt */
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "nsFileStream.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsEscape.h"
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "plstr.h"
|
||||
|
@ -345,17 +346,19 @@ nsFileURL::nsFileURL(const nsFileURL& inOther)
|
|||
//----------------------------------------------------------------------------------------
|
||||
nsFileURL::nsFileURL(const nsFilePath& inOther)
|
||||
//----------------------------------------------------------------------------------------
|
||||
: mURL(nsFileSpecHelpers::AllocCat(kFileURLPrefix, (const char*)inOther))
|
||||
: mURL(nsnull)
|
||||
{
|
||||
*this = inOther;
|
||||
} // nsFileURL::nsFileURL
|
||||
#endif
|
||||
|
||||
#ifndef XP_MAC
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsFileURL::nsFileURL(const nsFileSpec& inOther)
|
||||
: mURL(nsFileSpecHelpers::AllocCat(kFileURLPrefix, (const char*)nsFilePath(inOther)))
|
||||
: mURL(nsnull)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
*this = inOther;
|
||||
} // nsFileURL::nsFileURL
|
||||
#endif
|
||||
|
||||
|
@ -392,7 +395,20 @@ void nsFileURL::operator = (const nsFilePath& inOther)
|
|||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
delete [] mURL;
|
||||
mURL = nsFileSpecHelpers::AllocCat(kFileURLPrefix, (const char*)inOther);
|
||||
char* original = (char*)(const char*)inOther; // we shall modify, but restore.
|
||||
#ifdef XP_PC
|
||||
// because we don't want to escape the '|' character, change it to a letter.
|
||||
NS_ASSERTION(original[2] == '|', "No drive letter part!");
|
||||
original[2] = 'x';
|
||||
char* escapedPath = nsEscape(original, url_Path);
|
||||
original[2] = '|'; // restore it
|
||||
escapedPath[2] = '|';
|
||||
#else
|
||||
char* escapedPath = nsEscape(original, url_Path);
|
||||
#endif
|
||||
if (escapedPath)
|
||||
mURL = nsFileSpecHelpers::AllocCat(kFileURLPrefix, escapedPath);
|
||||
delete [] escapedPath;
|
||||
} // nsFileURL::operator =
|
||||
#endif
|
||||
|
||||
|
@ -401,8 +417,7 @@ void nsFileURL::operator = (const nsFilePath& inOther)
|
|||
void nsFileURL::operator = (const nsFileSpec& inOther)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
delete [] mURL;
|
||||
mURL = nsFileSpecHelpers::AllocCat(kFileURLPrefix, (const char*)nsFilePath(inOther));
|
||||
*this = nsFilePath(inOther);
|
||||
} // nsFileURL::operator =
|
||||
#endif
|
||||
|
||||
|
|
|
@ -62,45 +62,64 @@ NS_BASE char* nsEscape(const char * str, nsEscapeMask mask)
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
NS_BASE char* nsEscapeCount(const char * str, PRInt32 len, nsEscapeMask mask, PRInt32 * out_len)
|
||||
NS_BASE char* nsEscapeCount(
|
||||
const char * str,
|
||||
PRInt32 len,
|
||||
nsEscapeMask mask,
|
||||
PRInt32* out_len)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
int32 i, extra = 0;
|
||||
char *hexChars = "0123456789ABCDEF";
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
if(!str)
|
||||
return(0);
|
||||
int i, extra = 0;
|
||||
char* hexChars = "0123456789ABCDEF";
|
||||
|
||||
register const unsigned char* src = (unsigned char *) str;
|
||||
register const unsigned char* src = (const unsigned char *) str;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (!IS_OK(src[i]))
|
||||
extra+=2; /* the escape, plus an extra byte for each nibble */
|
||||
}
|
||||
{
|
||||
if (!IS_OK(*src++))
|
||||
extra += 2; /* the escape, plus an extra byte for each nibble */
|
||||
}
|
||||
|
||||
char* result = new char[len + extra + 1];
|
||||
if (!result)
|
||||
return(0);
|
||||
return 0;
|
||||
|
||||
register unsigned char* dst = (unsigned char *) result;
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
unsigned char c = src[i];
|
||||
if (IS_OK(c))
|
||||
{
|
||||
*dst++ = c;
|
||||
}
|
||||
else if (mask == url_XPAlphas && c == ' ')
|
||||
{
|
||||
*dst++ = '+'; /* convert spaces to pluses */
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst++ = HEX_ESCAPE;
|
||||
*dst++ = hexChars[c >> 4]; /* high nibble */
|
||||
*dst++ = hexChars[c & 0x0f]; /* low nibble */
|
||||
}
|
||||
}
|
||||
src = (const unsigned char *) str;
|
||||
if (mask == url_XPAlphas)
|
||||
{
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
unsigned char c = *src++;
|
||||
if (IS_OK(c))
|
||||
*dst++ = c;
|
||||
else if (c == ' ')
|
||||
*dst++ = '+'; /* convert spaces to pluses */
|
||||
else
|
||||
{
|
||||
*dst++ = HEX_ESCAPE;
|
||||
*dst++ = hexChars[c >> 4]; /* high nibble */
|
||||
*dst++ = hexChars[c & 0x0f]; /* low nibble */
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
unsigned char c = *src++;
|
||||
if (IS_OK(c))
|
||||
*dst++ = c;
|
||||
else
|
||||
{
|
||||
*dst++ = HEX_ESCAPE;
|
||||
*dst++ = hexChars[c >> 4]; /* high nibble */
|
||||
*dst++ = hexChars[c & 0x0f]; /* low nibble */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*dst = '\0'; /* tack on eos */
|
||||
if(out_len)
|
||||
|
@ -125,27 +144,24 @@ NS_BASE PRInt32 nsUnescapeCount(char * str)
|
|||
|
||||
while (*src)
|
||||
if (*src != HEX_ESCAPE)
|
||||
{
|
||||
*dst++ = *src++;
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
src++; /* walk over escape */
|
||||
if (*src)
|
||||
{
|
||||
{
|
||||
*dst = UNHEX(*src) << 4;
|
||||
src++;
|
||||
}
|
||||
}
|
||||
if (*src)
|
||||
{
|
||||
{
|
||||
*dst = (*dst + UNHEX(*src));
|
||||
src++;
|
||||
}
|
||||
}
|
||||
dst++;
|
||||
}
|
||||
}
|
||||
|
||||
*dst = 0;
|
||||
|
||||
return (int)(dst - str);
|
||||
|
||||
} /* NET_UnEscapeCnt */
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "nsFileStream.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsEscape.h"
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "plstr.h"
|
||||
|
@ -345,17 +346,19 @@ nsFileURL::nsFileURL(const nsFileURL& inOther)
|
|||
//----------------------------------------------------------------------------------------
|
||||
nsFileURL::nsFileURL(const nsFilePath& inOther)
|
||||
//----------------------------------------------------------------------------------------
|
||||
: mURL(nsFileSpecHelpers::AllocCat(kFileURLPrefix, (const char*)inOther))
|
||||
: mURL(nsnull)
|
||||
{
|
||||
*this = inOther;
|
||||
} // nsFileURL::nsFileURL
|
||||
#endif
|
||||
|
||||
#ifndef XP_MAC
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsFileURL::nsFileURL(const nsFileSpec& inOther)
|
||||
: mURL(nsFileSpecHelpers::AllocCat(kFileURLPrefix, (const char*)nsFilePath(inOther)))
|
||||
: mURL(nsnull)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
*this = inOther;
|
||||
} // nsFileURL::nsFileURL
|
||||
#endif
|
||||
|
||||
|
@ -392,7 +395,20 @@ void nsFileURL::operator = (const nsFilePath& inOther)
|
|||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
delete [] mURL;
|
||||
mURL = nsFileSpecHelpers::AllocCat(kFileURLPrefix, (const char*)inOther);
|
||||
char* original = (char*)(const char*)inOther; // we shall modify, but restore.
|
||||
#ifdef XP_PC
|
||||
// because we don't want to escape the '|' character, change it to a letter.
|
||||
NS_ASSERTION(original[2] == '|', "No drive letter part!");
|
||||
original[2] = 'x';
|
||||
char* escapedPath = nsEscape(original, url_Path);
|
||||
original[2] = '|'; // restore it
|
||||
escapedPath[2] = '|';
|
||||
#else
|
||||
char* escapedPath = nsEscape(original, url_Path);
|
||||
#endif
|
||||
if (escapedPath)
|
||||
mURL = nsFileSpecHelpers::AllocCat(kFileURLPrefix, escapedPath);
|
||||
delete [] escapedPath;
|
||||
} // nsFileURL::operator =
|
||||
#endif
|
||||
|
||||
|
@ -401,8 +417,7 @@ void nsFileURL::operator = (const nsFilePath& inOther)
|
|||
void nsFileURL::operator = (const nsFileSpec& inOther)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
delete [] mURL;
|
||||
mURL = nsFileSpecHelpers::AllocCat(kFileURLPrefix, (const char*)nsFilePath(inOther));
|
||||
*this = nsFilePath(inOther);
|
||||
} // nsFileURL::operator =
|
||||
#endif
|
||||
|
||||
|
|
|
@ -255,7 +255,7 @@ class NS_BASE nsFileSpec
|
|||
long parID,
|
||||
ConstStr255Param name);
|
||||
nsFileSpec(const FSSpec& inSpec)
|
||||
: mSpec(inSpec), mError(NS_OK) {}
|
||||
: mSpec(inSpec), mError(NS_OK), mPath(nsnull) {}
|
||||
void operator = (const FSSpec& inSpec)
|
||||
{ mSpec = inSpec; mError = NS_OK; }
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "FullPath.h"
|
||||
#include "FileCopy.h"
|
||||
#include "MoreFilesExtras.h"
|
||||
#include "nsEscape.h"
|
||||
|
||||
#include <Aliases.h>
|
||||
#include <Folders.h>
|
||||
|
@ -917,7 +916,7 @@ nsFilePath::nsFilePath(const char* inString, PRBool inCreateDirs)
|
|||
, mFileSpec(inString, inCreateDirs)
|
||||
{
|
||||
// Make canonical and absolute.
|
||||
char * path = MacFileHelpers::PathNameFromFSSpec( mFileSpec, TRUE );
|
||||
char * path = MacFileHelpers::PathNameFromFSSpec( mFileSpec, true );
|
||||
mPath = MacFileHelpers::EncodeMacPath(path, true, false);
|
||||
}
|
||||
|
||||
|
@ -928,7 +927,7 @@ nsFilePath::nsFilePath(const nsString& inString, PRBool inCreateDirs)
|
|||
, mFileSpec(nsAutoCString(inString), inCreateDirs)
|
||||
{
|
||||
// Make canonical and absolute.
|
||||
char * path = MacFileHelpers::PathNameFromFSSpec( mFileSpec, TRUE );
|
||||
char * path = MacFileHelpers::PathNameFromFSSpec( mFileSpec, true );
|
||||
mPath = MacFileHelpers::EncodeMacPath(path, true, false);
|
||||
}
|
||||
|
||||
|
@ -952,7 +951,7 @@ nsFilePath::nsFilePath(const nsFileURL& inOther)
|
|||
void nsFilePath::operator = (const nsFileSpec& inSpec)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
char * path = MacFileHelpers::PathNameFromFSSpec( inSpec.mSpec, TRUE );
|
||||
char * path = MacFileHelpers::PathNameFromFSSpec( inSpec.mSpec, true );
|
||||
delete [] mPath;
|
||||
mPath = MacFileHelpers::EncodeMacPath(path, true, false);
|
||||
mFileSpec = inSpec;
|
||||
|
@ -1032,8 +1031,17 @@ void nsFileURL::operator = (const nsFileSpec& inOther)
|
|||
{
|
||||
mFileSpec = inOther;
|
||||
delete [] mURL;
|
||||
char* path = MacFileHelpers::PathNameFromFSSpec( mFileSpec, TRUE );
|
||||
mURL = MacFileHelpers::EncodeMacPath(path, true, true);
|
||||
char* path = MacFileHelpers::PathNameFromFSSpec( mFileSpec, true );
|
||||
char* encodedPath = MacFileHelpers::EncodeMacPath(path, true, true);
|
||||
char* encodedURL = nsFileSpecHelpers::AllocCat(kFileURLPrefix, encodedPath);
|
||||
delete [] encodedPath;
|
||||
if (encodedURL[strlen(encodedURL) - 1] != '/' && inOther.IsDirectory())
|
||||
{
|
||||
mURL = nsFileSpecHelpers::AllocCat(encodedURL, "/");
|
||||
delete [] encodedURL;
|
||||
}
|
||||
else
|
||||
mURL = encodedURL;
|
||||
} // nsFileURL::operator =
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
|
Загрузка…
Ссылка в новой задаче