• 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 path] vs. CFURLCopyPath() and CFURLCopyStrictPath()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -[NSURL path] vs. CFURLCopyPath() and CFURLCopyStrictPath()


  • Subject: Re: -[NSURL path] vs. CFURLCopyPath() and CFURLCopyStrictPath()
  • From: Jerry Krinock <email@hidden>
  • Date: Mon, 09 Apr 2012 15:42:52 -0700

Thank you Jens and Charles for the additional tips.

So Apple provides three routines for getting the path component of a URL.  They all give different answers.

• -[NSURL path].  Mangles it, per documentation.  Not only does it strip the trailing slash, but it unescapes percent escapes.

• CFURLCopyPath().  According to documentation, "This function does not resolve the URL against its base and replaces all percent escape sequences."  Does that mean that it replaces percent escapes?  My interpretation is that it *does*, but in testing I see that it it does *not*.  It does not strip any leading slash.

• CFURLCopyStrictPath().  Ditto the above, except that it strips the leading slash.

Since the leading slash is part of the path according to RFC 3986, this means that the "Strict" method is not strict, and the non-strict method is strict.

CONCLUSION: CFURLCopyPath() is the winner, and I sent Apple a "not helpful" on the CFURL documentation.

TEST CODE:

NSString* s = @"http://example.com/path/to/id=8528/"; ;
NSLog(@"       given: %@", s) ;
NSURL* url = [NSURL URLWithString:s] ;
NSString* cocoaPath = [url path] ;
NSString* cfPath = [(NSString*)CFURLCopyPath((CFURLRef)url) autorelease] ;
NSString* cfstrictPath = [(NSString*)CFURLCopyStrictPath((CFURLRef)url, NULL) autorelease] ;
NSLog(@"   cocoaPath: %@", cocoaPath) ;
NSLog(@"      cfPath: %@", cfPath) ;
NSLog(@"cfstrictPath: %@", cfstrictPath) ;

RESULTS:

        given: http://example.com/path/to/id=8528/
    cocoaPath: /path/to/id=8528
       cfPath: /path/to/id=8528/
 cfstrictPath: path/to/id=8528/


_______________________________________________

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 path] "If the path has a trailing slash it is stripped" (From: Jerry Krinock <email@hidden>)
 >Re: -[NSURL path] "If the path has a trailing slash it is stripped" (From: Ken Thomases <email@hidden>)
 >Re: -[NSURL path] "If the path has a trailing slash it is stripped" (From: Jerry Krinock <email@hidden>)
 >Re: -[NSURL path] "If the path has a trailing slash it is stripped" (From: Jens Alfke <email@hidden>)
 >Re: -[NSURL path] "If the path has a trailing slash it is stripped" (From: Charles Srstka <email@hidden>)

  • Prev by Date: Re: -[NSURL path] "If the path has a trailing slash it is stripped"
  • Next by Date: Re: -[NSURL path] "If the path has a trailing slash it is stripped"
  • Previous by thread: Re: -[NSURL path] "If the path has a trailing slash it is stripped"
  • Next by thread: Re: -[NSURL path] "If the path has a trailing slash it is stripped"
  • Index(es):
    • Date
    • Thread