mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
fix bug 97983 [ExtractUrlPart allows no access to the directory part of the url] This patch introduces a new bitmask url_Path that allows accessing the whole path, moved url_Directory from path access to it's original meaning accessing the directory portion of the url. Also fixed some start/endposition calculations, r=dougt@netscape.com,sr=darin@netscape.com
This commit is contained in:
parent
511821a823
commit
36bc63e942
@ -167,6 +167,7 @@ interface nsIIOService : nsISupports
|
||||
const short url_Param = (1<<7);
|
||||
const short url_Query = (1<<8);
|
||||
const short url_Ref = (1<<9);
|
||||
const short url_Path = (1<<10);
|
||||
|
||||
/**
|
||||
* Get port from string.
|
||||
|
@ -544,7 +544,7 @@ nsIOService::ExtractUrlPart(const char *urlString, PRInt16 flag, PRUint32 *start
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRInt32 port;
|
||||
nsXPIDLCString dummyScheme, username, password, host, path, o_path;
|
||||
nsXPIDLCString dummyScheme, username, password, host, path;
|
||||
|
||||
rv = parser->ParseAtScheme(urlString,
|
||||
getter_Copies(dummyScheme),
|
||||
@ -577,7 +577,7 @@ nsIOService::ExtractUrlPart(const char *urlString, PRInt16 flag, PRUint32 *start
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_Directory) {
|
||||
if (flag == url_Path) {
|
||||
CalculateStartEndPos(urlString, path, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(path.get());
|
||||
@ -585,10 +585,10 @@ nsIOService::ExtractUrlPart(const char *urlString, PRInt16 flag, PRUint32 *start
|
||||
}
|
||||
|
||||
|
||||
nsXPIDLCString fileBaseName, fileExtension, param, query, ref;
|
||||
nsXPIDLCString directory, fileBaseName, fileExtension, param, query, ref;
|
||||
|
||||
rv = parser->ParseAtDirectory(path,
|
||||
getter_Copies(o_path),
|
||||
getter_Copies(directory),
|
||||
getter_Copies(fileBaseName),
|
||||
getter_Copies(fileExtension),
|
||||
getter_Copies(param),
|
||||
@ -598,6 +598,13 @@ nsIOService::ExtractUrlPart(const char *urlString, PRInt16 flag, PRUint32 *start
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
if (flag == url_Directory) {
|
||||
CalculateStartEndPos(urlString, directory, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(directory.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_FileBaseName) {
|
||||
CalculateStartEndPos(urlString, fileBaseName, startPos, endPos);
|
||||
if (urlPart)
|
||||
@ -606,28 +613,28 @@ nsIOService::ExtractUrlPart(const char *urlString, PRInt16 flag, PRUint32 *start
|
||||
}
|
||||
|
||||
if (flag == url_FileExtension) {
|
||||
CalculateStartEndPos(urlString, fileBaseName, startPos, endPos);
|
||||
CalculateStartEndPos(urlString, fileExtension, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(fileExtension.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_Param) {
|
||||
CalculateStartEndPos(urlString, fileBaseName, startPos, endPos);
|
||||
CalculateStartEndPos(urlString, param, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(param.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_Query) {
|
||||
CalculateStartEndPos(urlString, fileBaseName, startPos, endPos);
|
||||
CalculateStartEndPos(urlString, query, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(query.get());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (flag == url_Ref) {
|
||||
CalculateStartEndPos(urlString, fileBaseName, startPos, endPos);
|
||||
CalculateStartEndPos(urlString, ref, startPos, endPos);
|
||||
if (urlPart)
|
||||
*urlPart = nsCRT::strdup(ref.get());
|
||||
return NS_OK;
|
||||
|
@ -639,7 +639,7 @@ nsUrlbarHistory::VerifyAndCreateEntry(const PRUnichar * aSearchItem, PRUnichar *
|
||||
nsXPIDLCString filePath;
|
||||
nsCOMPtr<nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID);
|
||||
if (!ioService) return NS_ERROR_FAILURE;
|
||||
ioService->ExtractUrlPart(NS_ConvertUCS2toUTF8(aSearchItem).get(), nsIIOService::url_Directory, 0, 0, getter_Copies(filePath));
|
||||
ioService->ExtractUrlPart(NS_ConvertUCS2toUTF8(aSearchItem).get(), nsIIOService::url_Path, 0, 0, getter_Copies(filePath));
|
||||
|
||||
// Don't bother checking for hostname if the search string
|
||||
// already has a filepath;
|
||||
@ -647,7 +647,7 @@ nsUrlbarHistory::VerifyAndCreateEntry(const PRUnichar * aSearchItem, PRUnichar *
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
ioService->ExtractUrlPart(NS_ConvertUCS2toUTF8(aMatchStr).get(), nsIIOService::url_Directory, 0, 0, getter_Copies(filePath));
|
||||
ioService->ExtractUrlPart(NS_ConvertUCS2toUTF8(aMatchStr).get(), nsIIOService::url_Path, 0, 0, getter_Copies(filePath));
|
||||
|
||||
// If the match string doesn't have a filepath
|
||||
// we need to do nothing here, return.
|
||||
|
Loading…
Reference in New Issue
Block a user