NSURL troubles: Apple docset URLs with multiple fragment identifiers

Gerd Knops <[email protected]> Wed, 29 Feb 2012 12:42:46 -0600
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
Hi Everyone,

I am having a hard time converting URL strings pointing into Apple's =
docsets into actual URLs. Here is an example, which works fine when =
copying and pasting into Safari:

=
file:///Library/Developer/Documentation/DocSets/com.apple.adc.documentatio=
n.AppleLion.CoreReference.docset/Contents/Resources/Documents/index.html#d=
ocumentation/Cocoa/Reference/NSTokenFieldDelegate_Protocol/Reference/Refer=
ence.html#//apple_ref/occ/intfm/NSTokenFieldDelegate/tokenField:shouldAddO=
bjects:atIndex:

However a simple [NSURL URLWithString:urlString] returns nil when =
presented with the above URL. After adding percent escapes  (which =
converts the '#' fragment identifiers into '%23') the URL can be =
created, but it does no longer work (eg when using NSWorkspace's =
openURL: method).

Looking closer at the URL there is something peculiar: It has two =
fragment identifiers. Safari simply appears to be ignoring the =
'index.html#' bit, and ends up with that Reference.html file, which it =
opens and then jumps to the location indicated by the second fragment.

Any way to make this into a valid URL?

Thanks

Gerd