views:

30

answers:

0

Steps:

Environment: OS X 10.6.4 Xcode 3.2.1

  1. Create a new "Application" project.
  2. Open the supplied application delegate.
  3. Add an NSString * property.
  4. In -applicationDidFinishLaunching: set the string property to @"/TestString%".
  5. Open up the NIB.
  6. Drag an NSPathControl onto the application window.
  7. Bind the NSPathControl's value binding to the property created in step 3.
  8. Run the application
  9. View the console.

You should see the following assertion and the path control will not display:

2010-09-15 13:23:39.043 NSPathControlPercentString[83066:a0f] *** Assertion failure in -[NSPathComponentCell _objectValue:forString:errorDescription:], /SourceCache/AppKit/AppKit-1038.32/AppKit.subproj/NSCell.m:1531
2010-09-15 15:33:04.193 NSPathControlPercentString[84028:a0f] Invalid parameter not satisfying: aString != nil

If you remove the percent sign from the string in step 4 the assertion will go away and the path control will display properly.

I have tried the following characters and none of them cause the same issue (make sure to escape double quote and backslash):

!@#$^&*()_-+=:;'|"\?.,<>~`

After doing some debugging I tracked this down to this method supporting percent escapes. e.g. if you use the string @"/Test%20string" the result will display "Test string" converting the %20 to a space character.

I haven't found this behavior documented anywhere. Am I missing it?

I encountered this issue because I was using -[NSBrowser path] to mirror the browser's path on an NSPathControl. If the contents of a selected browser cell contained a % sign the whole NSPathControl would fail (QA is great for turning up things like that—many thanks to them).

My best guess is that it attempts to convert the string to an NSURL internally which fails returning nil which triggers the exception. This is reinforced by the fact that if you omit the leading / in your string you see the following message:

2010-09-15 15:35:55.543 NSPathControlPercentString[84100:a0f] *** -[NSURL initWithScheme:host:path:]: path test!@#$^&*()_-+=:;'|"\?.,<>~` is not absolute.

But this is still missing something because -initWithScheme:host:path: is documented as adding the required precent escapes, and those methods which could be calling -initWithScheme:host:path: and are not documented as adding the escapes (e.g. -initWithString) are documented as requiring escapes for characters which cause no issues, namely :, /, #, ;, and @.

I'm planning to file a bug with Apple about it but I wanted to get this documented somewhere and to make sure I'm not missing something first.


For anybody finding this question looking for a solution my solution was to manually implement the getter of the property bound to the NSPathControl to return an escaped string using -stringByAddingPercentEscapesUsingEncoding: and NSUTF8StringEncoding.


Since nobody had any input I went ahead and filed this with Apple. Radar Bug ID #8452431.