Re: NSURL creation problem with colon: a partial workaround
Re: NSURL creation problem with colon: a partial workaround
- Subject: Re: NSURL creation problem with colon: a partial workaround
- From: Mike Abdullah <email@hidden>
- Date: Thu, 18 Dec 2008 15:58:40 +0000
According to the RFC specs referenced by the NSURL documentation, the
colon is a reserved character. You should percent escape it before
using it as a relative path. I believe that would be:
NSURL * url2 = [NSURL fileURLWithPath:@"/root/"];
NSURL * url3 = [NSURL URLWithString:@"file:test" relativeToURL:url2];
On 18 Dec 2008, at 14:05, Jérome Laurens wrote:
Hi list,
I have a relative path with colons "file:test", and I would like to
create a NSURL relative to a given base URL "file://localhost/root/".
This does not work as expected.
Consider the simple URL creation method
NSURL * url1 = [NSURL fileURLWithPath:@"/root/file:test"];
The url is properly created and its absoluteURL reads
file://localhost/root/file:test/
If I use a base URL things go wrong
NSURL * url2 = [NSURL fileURLWithPath:@"/root/"];
NSURL * url3 = [NSURL URLWithString:@"file:test" relativeToURL:url2];
The absolute URL of url3 reads
file:test
which is not the expected value.
Apparently NSURL parses the string as if there were no base URL at
all,
which produces a wrong value.
Fortunately, there is a warkaround by prepending "./" to the
relative path.
NSURL * url4 = [NSURL URLWithString:@"./file:test"
relativeToURL:url2];
The absolute URL of url4 reads
file://localhost/root/file:test
what is the expected value.
But the standardizedURL still reads the wrong value
file:test
So prepending "./" to the relative path is just a partial workaround.
Regards
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden