Zero-width space crashes Safari

Here is a recipe for making Safari hang.

1. In any text editor, create a simple Web page containing the string "http://www.apple.com". Define the page's encoding as UTF-8.

2. After the "//" and each of the two "."s in the URL, insert the zero-width space Unicode character, which W3C recommends as a way to specify where a long string like a URL should be wrappable. You can insert it by typing
"& # x 2 0 0 b ;"
(omitting the spaces).

3. Save the page.

4. Open the page in Safari. It should look correct, with the zero-width spaces invisible. If the URL happens to start near the end of a line, it should wrap appropriately where you inserted a zero-width space.

5. Make Safari display a page preview in the "Print..." dialog.

6. Save the print preview as a PDF file.

7. Open the PDF file with Preview.

8. Drag across the URL to select it, copy it, and paste it into the address bar of Safari.

9. The URL will look good, but Safari will be paralyzed as soon as you have pasted the URL, and you'll need to force-quit Safari.

G4 tower, Mac OS X (10.4.1)

Posted on Jul 29, 2006 6:53 PM

Reply
6 replies

Jul 30, 2006 3:59 AM in response to Jonathan Pool

2. After the "//" and each of the two "."s in the
URL, insert the zero-width space Unicode character,
which W3C recommends as a way to specify where a long
string like a URL should be wrappable. You can insert
it by typing
"& # x 2 0 0 b ;"


Have you tried this by inserting the real character via the Character Palette?

In urls, special characters are supposed to be escaped using % rather than &#x.

Jul 30, 2006 9:51 AM in response to Tom Gewecke

I just tried that, and it didn't paralyze Safari. The extra zero-width spaces inside the site portion of the URL didn't prevent Safari from finding the site. But zero-width spaces after the site portion of the URL (the file specification) did prevent Safari from finding the file. (Also, strangely, in the Character Palette, when the mouse hovers over the characters 200B, 200C, 200D, and 200E, in addition to the usual diagnostic yellow-rectangle tip, another tip appears covering part of it saying "Hand made carpet".)

This bug arose from my attempt to format URLs in an HTML document with reasonable line wrapping. Safari doesn't wrap on "." or "/", so URLs don't contain enough wrapping-eligible characters. So I followed the W3C recommendation and inserted zero-width spaces, and then the URLs wrapped appropriately, without showing any extra spaces. Since only the visible text contains extra spaces, and not the links, users clicking on a URL link go to the correct destination. But, if I make a PDF document out of the HTML document, the links disappear, leaving only their visible text, which looks good to the eye but still contains invisible extra spaces, so if the user of the PDF document asks Acrobat to reconstruct links from the URLs, or copies the URL texts and pastes them into a browser, the results are bad, in various ways, depending on the application, with the invisible spaces converted to normal spaces, or to "!", or to a curly left angle bracket, or (as reported here) freezing the browser.

Jul 30, 2006 11:17 AM in response to Jonathan Pool

One more observation from further experimentation:

Both Mac-based methods for creating PDF files from Safari (Print Preview saved to disk, and Save as PDF) preserve invisible spaces as characters and therefore cause problems when users copy URLs containing such spaces and paste them into browsers' address bars.

But Adobe's "Adobe PDF" printer driver, which is part of Acrobat, seems not to have that problem. It seems to ignore those zero-width spaces when it creates a PDF file, and the resulting URLs can be copied and pasted into browsers and work correctly.

Jul 30, 2006 11:42 AM in response to Jonathan Pool

One amendment to that observation:

The good behavior I described occurs if you open the Adobe-created PDF file with Preview.

But, if you open it with Acrobat Reader or Acrobat, something is still present where the zero-width spaces were, and you see it if you copy the URL and paste it into a browser's address bar. It's different between Acrobat Reader and Acrobat, but in both cases in stops the browser from recognizing the URL.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Zero-width space crashes Safari

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.