- Api nsILocalFile::AppendRelativePath() added to interface

- nsILocalFile::Append() returns error uniformly on all platforms if
more than one component of path is being appended.
This commit is contained in:
dp%netscape.com 2000-05-05 05:47:32 +00:00
Родитель a5c995336b
Коммит 7290a04bc1
5 изменённых файлов: 63 добавлений и 6 удалений

Просмотреть файл

@ -64,6 +64,18 @@ interface nsILocalFile : nsIFile
[noscript] PRLibraryStar load();
readonly attribute PRInt64 diskSpaceAvailable; // maybe we should put this somewhere else.
/**
* appendRelativePath
*
* Append a relative path to the current path of the nsILocalFile object.
*
* @param relativeFilePath
* relativeFilePath is a native relative path. For security reasons,
* this cannot contain .. or cannot start with a directory separator
*/
void appendRelativePath([const] in string relativeFilePath);
void appendRelativeUnicodePath([const] in wstring relativeFilePath);
};
%{C++

Просмотреть файл

@ -240,6 +240,11 @@ nsLocalFile::AppendUnicode(const PRUnichar *node)
SET_UCS( Append , node);
}
NS_IMETHODIMP
nsLocalFile::AppendRelativeUnicodePath(const PRUnichar *node)
{
SET_UCS( AppendRelativePath , node);
}
NS_IMETHODIMP
nsLocalFile::GetUnicodeLeafName(PRUnichar **aLeafName)
{
GET_UCS(GetLeafName, aLeafName);

Просмотреть файл

@ -1119,9 +1119,18 @@ nsLocalFile::Create(PRUint32 type, PRUint32 attributes)
return NS_ERROR_FILE_UNKNOWN_TYPE;
}
NS_IMETHODIMP
nsLocalFile::Append(const char *node)
{
if (!node || (strstr(node, ":") != nsnull))
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
return AppendRelativePath(node);
}
NS_IMETHODIMP
nsLocalFile::AppendRelativePath(const char *node)
{
if ( (node == nsnull) )
return NS_ERROR_FILE_UNRECOGNIZED_PATH;

Просмотреть файл

@ -417,6 +417,28 @@ nsLocalFile::Append(const char *fragment)
{
NS_ENSURE_ARG(fragment);
CHECK_mPath();
// only one component of path can be appended
if (strstr(fragment, "/") != nsnull)
{
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
}
return AppendRelativePath(fragment);
}
NS_IMETHODIMP
nsLocalFile::AppendRelativePath(const char *fragment)
{
NS_ENSURE_ARG(fragment);
CHECK_mPath();
// Cannot start with a '/' and no .. allowed in the fragment
if ((*fragment == '/') || (strstr(fragment, "..") != nsnull))
{
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
}
char * newPath = (char *)nsAllocator::Alloc(strlen(mPath) +
strlen(fragment) + 2);
if (!newPath)

Просмотреть файл

@ -694,11 +694,20 @@ nsLocalFile::Create(PRUint32 type, PRUint32 attributes)
NS_IMETHODIMP
nsLocalFile::Append(const char *node)
{
if ( (node == nsnull) ||
(*node == '/') ||
(strstr(node, "..") != nsnull) ||
(_mbschr((const unsigned char*) node, '\\') != nsnull) ||
(strchr(node, '/') != nsnull) )
// Append only one component. Check for subdirs.
if (!node || (_mbschr((const unsigned char*) node, '\\') != nsnull))
{
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
}
return AppendRelativePath(node);
}
NS_IMETHODIMP
nsLocalFile::AppendRelativePath(const char *node)
{
// Cannot start with a / or have .. or have / anywhere
if (!node || (*node == '/') || (strstr(node, "..") != nsnull) ||
(strchr(node, '/') != nsnull))
{
return NS_ERROR_FILE_UNRECOGNIZED_PATH;
}