Conversion from NSURL to a classic HFS path is incorrect when POSIX path contains a legal ":" character

Number:rdar://9907291855 Date Originated:18Sept19
Status:Open Resolved:
Product:macOS, Foundation Product Version:10.14
Classification:Incorrect/Unexpected Behavior Reproducible:always

When calling CFURLCopyFileSystemPath(path, 1) in order to get a HFS style path, this returns incorrect results when the path contains a folder with a colon (or slash) in its name.

I understand that this particular function is marked deprecated, but HFS paths are still needed in some parts of the OS API, e.g. when passing file refs to AppleScripts, and so this should still work correctly, at least, when needed. And I'm suspect it used to work correctly, but got broken a while ago.

How to reproduce the bug:

In Xcode, create a new "command line" project and use the attached main.m file. Run the program - it'll create a file named "FolderEndingInSlash/" inside "/tmp", when you look at the tmp folder with Finder (where ":" in a POSIX file name appears as a "/").

Then it calls CFURLCopyFileSystemPath to get the HFS path, which correctly would be:

    Macintosh HD:private:tmp:FolderEndingInSlash/

However, the "/" at the end is missing.

The reason for this bug seems to be that this function calls stringByStandardizingPath afterwards, which strips the slash by mistake.

You can read more about this here:


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!