fixes bug 249282 "Permit mixing of \ and / in file:// URLs under Win32" r=biesi sr=bzbarsky

This commit is contained in:
darin%meer.net 2004-08-04 17:08:27 +00:00
Родитель 646dbcbcbd
Коммит c41f4b4ba3
5 изменённых файлов: 79 добавлений и 3 удалений

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

@ -1,4 +1,5 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* vim:set ts=4 sw=4 sts=4 et cindent: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -575,6 +576,36 @@ net_FilterURIString(const char *str, nsACString& result)
return writing;
}
#if defined(XP_WIN) || defined(XP_OS2)
PRBool
net_NormalizeFileURL(const nsACString &aURL, nsCString &aResultBuf)
{
PRBool writing = PR_FALSE;
nsACString::const_iterator beginIter, endIter;
aURL.BeginReading(beginIter);
aURL.EndReading(endIter);
const char *begin = beginIter.get();
for (const char *s = begin; s != endIter.get(); ++s)
{
if (*s == '\\')
{
writing = PR_TRUE;
if (s > begin)
aResultBuf.Append(begin, s - begin);
aResultBuf += '/';
begin = s + 1;
}
}
if (writing && s > begin)
aResultBuf.Append(begin, s - begin);
return writing;
}
#endif
//----------------------------------------------------------------------------
// miscellaneous (i.e., stuff that should really be elsewhere)
//----------------------------------------------------------------------------

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

@ -141,6 +141,24 @@ inline PRBool net_IsValidScheme(const nsAFlatCString &scheme)
*/
NS_HIDDEN_(PRBool) net_FilterURIString(const char *str, nsACString& result);
#if defined(XP_WIN) || defined(XP_OS2)
/**
* On Win32 and OS/2 system's a back-slash in a file:// URL is equivalent to a
* forward-slash. This function maps any back-slashes to forward-slashes.
*
* @param aURL
* The URL string to normalize (UTF-8 encoded). This can be a
* relative URL segment.
* @param aResultBuf
* The resulting string is appended to this string. If the input URL
* is already normalized, then aResultBuf is unchanged.
*
* @returns false if aURL is already normalized. Otherwise, returns true.
*/
NS_HIDDEN_(PRBool) net_NormalizeFileURL(const nsACString &aURL,
nsCString &aResultBuf);
#endif
/*****************************************************************************
* generic string routines follow (XXX move to someplace more generic).
*/

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

@ -110,10 +110,18 @@ net_GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
NS_ERROR("Only nsILocalFile supported right now");
return rv;
}
const nsACString *specPtr;
nsCAutoString buf;
if (net_NormalizeFileURL(aURL, buf))
specPtr = &buf;
else
specPtr = &aURL;
nsCAutoString directory, fileBaseName, fileExtension;
rv = net_ParseFileURL(aURL, directory, fileBaseName, fileExtension);
rv = net_ParseFileURL(*specPtr, directory, fileBaseName, fileExtension);
if (NS_FAILED(rv)) return rv;
nsCAutoString path;

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

@ -106,10 +106,18 @@ net_GetFileFromURLSpec(const nsACString &aURL, nsIFile **result)
NS_ERROR("Only nsILocalFile supported right now");
return rv;
}
const nsACString *specPtr;
nsCAutoString buf;
if (net_NormalizeFileURL(aURL, buf))
specPtr = &buf;
else
specPtr = &aURL;
nsCAutoString directory, fileBaseName, fileExtension;
rv = net_ParseFileURL(aURL, directory, fileBaseName, fileExtension);
rv = net_ParseFileURL(*specPtr, directory, fileBaseName, fileExtension);
if (NS_FAILED(rv)) return rv;
nsCAutoString path;

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

@ -165,8 +165,19 @@ nsFileProtocolHandler::NewURI(const nsACString &spec,
if (!url)
return NS_ERROR_OUT_OF_MEMORY;
const nsACString *specPtr = &spec;
#if defined(XP_WIN) || defined(XP_OS2)
nsCAutoString buf;
if (net_NormalizeFileURL(spec, buf))
specPtr = &buf;
#endif
// XXX perhaps we should convert |charset| to whatever the system charset
// is so that nsStandardURL will normalize our URL string properly?
nsresult rv = url->Init(nsIStandardURL::URLTYPE_NO_AUTHORITY, -1,
spec, charset, baseURI);
*specPtr, charset, baseURI);
if (NS_FAILED(rv)) return rv;
return CallQueryInterface(url, result);