Discussion:
wxArchiveFSHandler with # in path
Kobus Grobler
2014-04-11 07:20:13 UTC
Permalink
Hi

OS: Windows (and other I would think)
wx Version: wxWidgets 3.0

There seems to be an issue with the way wxArchiveFSHandler (and
wxFileSystemHandler) handles a # in the path provided to it.

Let's say you have a zip file in a folder with a # in it, like so:
C:/work/test#1/data.zip

The url to open a file "test.txt" in the archive would be:
file:C:/work/test#1/data.zip#zip:test.txt

Then wxArchiveFSHandler will not find the file data.zip because of the #
earlier in the path.

The problem is when wxArchiveFSHandler uses wxFileSystemHandler to open
the file because wxFileSystemHandler::GetRightLocation()
returns "C:/work/test" instead of "C:/work/test#1/data.zip" due to the #
in the path.

I came across this because some users use "#" in their user name, then
files in their user directory is inaccessible using wxFileSystemHandler.

I'm not sure how to work around this or if there is a way to escape the
path?

For reference, here is the code from wxWidgets 3.0 (I think this is an
issue with earlier versions as well):

wxString wxFileSystemHandler::GetRightLocation(const wxString& location)
{
int i, l = location.length();
int l2 = l + 1;

for (i = l-1;
(i >= 0) &&
((location[i] != wxT(':')) || (i == 1) || (location[i-2] ==
wxT(':')));
i--)
{
if (location[i] == wxT('#')) l2 = i + 1;
}
if (i == 0) return wxEmptyString;
else return location.Mid(i + 1, l2 - i - 2);
}

Thanks
Kobus
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Vadim Zeitlin
2014-04-11 17:38:13 UTC
Permalink
On Fri, 11 Apr 2014 09:20:13 +0200 Kobus Grobler wrote:

KG> There seems to be an issue with the way wxArchiveFSHandler (and
KG> wxFileSystemHandler) handles a # in the path provided to it.
KG>
KG> Let's say you have a zip file in a folder with a # in it, like so:
KG> C:/work/test#1/data.zip
KG>
KG> The url to open a file "test.txt" in the archive would be:
KG> file:C:/work/test#1/data.zip#zip:test.txt

I don't know how is this URL constructed, but I believe the problem is
with constructing it: the "#" should be escaped (i.e. appear as "%23").
IOW we need to fix the code building this URI, do you know where is this
done?

Regards,
VZ
--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/
Kobus Grobler
2014-04-16 10:33:24 UTC
Permalink
Post by Vadim Zeitlin
KG> There seems to be an issue with the way wxArchiveFSHandler (and
KG> wxFileSystemHandler) handles a # in the path provided to it.
KG>
KG> C:/work/test#1/data.zip
KG>
KG> file:C:/work/test#1/data.zip#zip:test.txt
I don't know how is this URL constructed, but I believe the problem is
with constructing it: the "#" should be escaped (i.e. appear as "%23").
IOW we need to fix the code building this URI, do you know where is this
done?
If you use wxURI::wxURI() to encode the path, it escapes everything
except '#' (sees it as URI fragment), so while it seemed to work at
first for encoding file paths, it does not work if your file path
contains a #.

wxFileSystem::FileNameToURL() is the correct one to use in this case.

Thank you Vadim.

Best
Kobus
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Loading...