Friday, May 17, 2013

Why can't I copy and paste a URL from a Gmail subject line?

Sometimes I send myself quick emails with only the URL of a website pasted into the subject line. Unfortunately, I have been frustrated by not being able to copy and paste those URLs from Gmail into a browser from Internet Explorer 10. This does not seem to affect Chrome.


TL;DR

If you are having trouble copying and pasting a URL from a Gmail subject line, paste it here and click Go:


Detail


Steps to reproduce:

  1. Visit a website:
  2. Copy the URL and send it to your Gmail account as the subject line.
  3. Open your Gmail account and copy the URL from the email you just sent yourself:
  4. Paste this URL into your browser's address bar.
  5. See the result:


Why does this happen?

It seems that Google must be inserting a special character called a Zero Width Space (Unicode 8203) at certain positions in the URL to prevent copying and pasting. I can only presume that this is some kind of security measure. For example, the URL I used in this example actually looked like this behind the scenes: http://www.iana.org/?domains/re?served, where the question marks (?) are the special zero width space characters.

Point to note: the DNS protocol seems to ignore this character. Pasting http://example.iana.org/ (which mapped to http://exa?mple.iana.?org/ when I tried it) into the browser will work fine.

The value is not a copy / paste artefact; it is in the DOM node value:
document.getElementById(':np').firstChild.nodeValue 
"http://www​.iana.org/​domains/re​served"
document.getElementById(':np').firstChild.nodeValue.length 
39

'http://www.iana.org/domains/reserved'.length 
36

0 comments:

Post a Comment