Watch out for Unicode in NSStrings!

Originator:jed.twoPOINTzero
Number:rdar://23063249 Date Originated:11-Oct-2015
Status:Open Resolved:No
Product:Developer Tools Product Version:Xcode 6.2
Classification:2 — Important Reproducible:Always
 
Summary:
If I put a right-to-left mark in a UITextField, so its contents look like this: 
“Regular Text ‮Watch out for Unicode‬”, then NSLog the UITextField, the output looks like this:

<UITextField: 0x7f9321735810; frame = (27 318.5; 348 30); text = 'Regular Text ‮Watch out f...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7f93215a6e50>; layer = <CALayer: 0x7f9321733290>>
This can be a problem, because the output is illegible after the text.

Steps to Reproduce:
1. Create a new iOS app (probably Mac, too)
2. Add a UITextField, and connect it to an IBOutlet in the view controller.
3. Paste the text between the quotes into a UITextField while running the app.
4. NSLog the UITextField property

Expected Results:
I expected to see something like this:

<UITextField: 0x7f9321735810; frame = (27 318.5; 348 30); text = 'Regular Text ‮Watch out f‬...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7f93215a6e50>; layer = <CALayer: 0x7f9321733290>>

That has a POP DIRECTIONAL FORMATTING (U+202C) character immediately before the ... of the text property.


Actual Results:
I got these results:

<UITextField: 0x7f9321735810; frame = (27 318.5; 348 30); text = 'Regular Text ‮Watch out f...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7f93215a6e50>; layer = <CALayer: 0x7f9321733290>>


Version:
Xcode Version 6.2 (6C131e)
OS X Yosemite 10.10.4 (14E46)

Notes:
Inserting a POP DIRECTIONAL FORMATTING (U+202C) character immediately before the end of all user-inputted strings can mitigate this problem.

Configuration:


Attachments:


———————————————————
ADDED 27-APR-2016

A possible issue that could occur with this is when a website or email displays a domain name that appears to be from Apple: ‮moc.elppa.stnuocca.net‬, which is really from [U+202E]moc.elppa.stnuocca.net.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com 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!