• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSURL creation problem with colon: a partial workaround
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >NSURL creation problem with colon: a partial workaround (From: Jérome Laurens <email@hidden>)

  • Prev by Date: Using a NSCollectionView in a table cell.
  • Next by Date: [Q] What type the Final Cut Pro expect when a file is drag&dropped to its project?
  • Previous by thread: NSURL creation problem with colon: a partial workaround
  • Next by thread: NSToolbar Error
  • Index(es):
    • Date
    • Thread