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%3D8528/"; ;
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%3D8528/
    cocoaPath: /path/to/id=8528
       cfPath: /path/to/id%3D8528/
 cfstrictPath: path/to/id%3D8528/


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to