Zero-width characters embedded in phone number whenever they are copied from the macOS address book

contactsunicode

Whenever I use Contacts.app to fill out a form on a website, I have a problem with any phone number field.

Contacts.app adds unicode "left-to-right override" (U+202D codepoint: E2 80 AD in UTF-8 contexts, 20 2D in UTF-16 contexts) before the first digit, and "pop directional formatting" (U+202C codepoint: E2 80 AC in UTF-8 contexts, 20 2C in UTF-16 contexts) after the last digit. Many websites get upset by this, because those are not recognised as valid phone number digits. As they are zero-width symbols, the first few times I saw this problem I didn't even understand what was going wrong.

Note that this still happens if I turn off JavaScript or use a desktop text editor like TextWrangler (TextWrangler is how I originally found out which zero-width symbols were being inserted); as it happens, I only care about websites because websites are the only thing which validates that phone numbers match a pattern such as the regex [0-9()+\s]*

This happens with all phone numbers in Contacts, regardless of whose (some are formatted as UK, some as USA, some as German).

Method: open Contacts.app, select any person, double (or triple) click on a phone number to select all of it, ⌘C-⌘V to copy-paste; if I paste into an app which shows non-printable characters like TextWrangler then I can see their existence, if I paste into a web browser it's present but zero-width, as arrow keys 'stick' at those positions and the delete key does in fact remove them.

It happens as described in both Safari and Chrome. In Firefox, it behaved slightly differently, and seemed to automatically delete the extra characters as soon as I pass through them with my arrow keys (?!).

How do I stop Contacts.app from adding these unicode symbols?

Best Answer

update 11/2020: It seems like this may be finally fixed in macOS 11. When I just tried it, copying a phone number using the normal ⌘command + C did not add the extra gremlins. Can anyone else confirm?


This isn't an answer but I wanted to add a screenshot as some people have requested it.

I noticed this bug as well (as recently as 10.15.7) and was glad to find this already reported, and surprised it hasn't received more attention.

I filed bugs #47763641 & #5235503 with Apple, hopefully they will notice. I encourage others to report it.

Here are steps to repro & a screenshot that shows the issue:

  1. From Contacts.app, right-click → Copy on a phone number.
  2. Paste into Sublime Text or any other plaintext editor.
  3. Save as test.txt
  4. Open in a Hex Editor, I used Hex Fiend in this example
  5. You can now see the extra bytes (I highlighted them below)

zwsp-chars-screenshot

a couple of bits of information:

  1. This seems to only affect phone# fields. Others such as email, addresses, notes etc don't exhibit this bug.
  2. If, instead of using ⌘command + A (select-all), you very carefully select just from the start of the phone# to the end and then copy, the unwanted zwsp characters aren't copied.

My workaround for now is an Alfred workflow that I mapped to ⌘⇧C that copies the selected field and trims the whitespace. Not exactly elegant, but it works well enough until Apple fixes this (which they may have as of 11.0)

Related Question