Update wxWebFileHandler to handle paths with fragments correctly, some backends pass this to the handler and some don't so we strip it if necessary.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68516 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -52,11 +52,20 @@ wxWebFileHandler::wxWebFileHandler()
|
|||||||
|
|
||||||
wxFSFile* wxWebFileHandler::GetFile(const wxString &uri)
|
wxFSFile* wxWebFileHandler::GetFile(const wxString &uri)
|
||||||
{
|
{
|
||||||
//We iterate through the string to see if there is a protocol description
|
//If there is a fragment at the end of the path then we need to strip it
|
||||||
int start = -1;
|
//off as not all backends do this for us
|
||||||
for(int i = 0; i < uri.length(); i++)
|
wxString path = uri;
|
||||||
|
size_t hashloc = uri.find('#');
|
||||||
|
if(hashloc != wxString::npos)
|
||||||
{
|
{
|
||||||
if(uri[i] == ';' && uri.substr(i, 10) == ";protocol=")
|
path = uri.substr(0, hashloc);
|
||||||
|
}
|
||||||
|
|
||||||
|
//We iterate through the string to see if there is a protocol description
|
||||||
|
size_t start = wxString::npos;
|
||||||
|
for(size_t i = 0; i < path.length(); i++)
|
||||||
|
{
|
||||||
|
if(path[i] == ';' && path.substr(i, 10) == ";protocol=")
|
||||||
{
|
{
|
||||||
start = i;
|
start = i;
|
||||||
break;
|
break;
|
||||||
@@ -64,32 +73,32 @@ wxFSFile* wxWebFileHandler::GetFile(const wxString &uri)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//We do not have a protocol string so we just pass the path withouth the
|
//We do not have a protocol string so we just pass the path withouth the
|
||||||
if(start == -1)
|
if(start == wxString::npos)
|
||||||
{
|
{
|
||||||
size_t doubleslash = uri.find("//");
|
size_t doubleslash = path.find("//");
|
||||||
//The path is incorrectly formed without // after the scheme
|
//The path is incorrectly formed without // after the scheme
|
||||||
if(doubleslash == wxString::npos)
|
if(doubleslash == wxString::npos)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
wxString fspath = "file:" +
|
wxString fspath = "file:" +
|
||||||
EscapeFileNameCharsInURL(uri.substr(doubleslash + 2));
|
EscapeFileNameCharsInURL(path.substr(doubleslash + 2));
|
||||||
return m_fileSystem->OpenFile(fspath);
|
return m_fileSystem->OpenFile(fspath);
|
||||||
}
|
}
|
||||||
//Otherwise we need to extract the protocol
|
//Otherwise we need to extract the protocol
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int end = uri.find('/', start);
|
size_t end = path.find('/', start);
|
||||||
//For the path to be valid there must to a path after the protocol
|
//For the path to be valid there must to a path after the protocol
|
||||||
if(end == wxString::npos)
|
if(end == wxString::npos)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
wxString mainpath = uri.substr(0, start);
|
wxString mainpath = path.substr(0, start);
|
||||||
wxString archivepath = uri.substr(end);
|
wxString archivepath = path.substr(end);
|
||||||
wxString protstring = uri.substr(start, end - start);
|
wxString protstring = path.substr(start, end - start);
|
||||||
wxString protocol = protstring.substr(10);
|
wxString protocol = protstring.substr(10);
|
||||||
//We can now construct the correct path
|
//We can now construct the correct path
|
||||||
size_t doubleslash = uri.find("//");
|
size_t doubleslash = path.find("//");
|
||||||
//The path is incorrectly formed without // after the first protocol
|
//The path is incorrectly formed without // after the first protocol
|
||||||
if(doubleslash == wxString::npos)
|
if(doubleslash == wxString::npos)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user