How Twitter wraps URLs with t.co

Updated on Sat, 2012-08-25 12:23

Twitter uses twitter-text to parse status bodies and extract the entities, including URLs, that are returned with tweet responses. To understand the types of http and https-based URLs that our parser will extract and wrap with t.co, peruse the URL conformance tests.

At this time, the general rule of thumb as to which URLs will be wrapped in t.co:

  • The URL must be a fully qualified HTTP or HTTPs-based URL Beginning October 10, Twitter will begin wrapping links without protocols in addition to fully qualified HTTP or HTTPs URLs.
  • Trailing periods and commas, unless URL-encoded, are ignored and not considered part of a URL. Two URLs connected by a period or comma will not be parsed.
  • The URL should not include login information. ( https://user:[email protected]/ will not be wrapped )

We're frequently making improvements to our parsing engine and because twitter-text is hosted on Github, you're welcome to submit pull requests for bug fixes or parsing improvements.

twitter-text for your programming language

twitter-text URL extraction conformance tests as of Nov 02, 2011

  1. urls:
  2.     - description: "Autolink URL with pipe character"
  3.       text: "text http://example.com/pipe|character?yes|pipe|character"
  4.       expected: "text <a href=\"http://example.com/pipe|character?yes|pipe|character\">http://example.com/pipe|character?yes|pipe|character</a>"
  5.  
  6.     - description: "Autolink trailing url"
  7.       text: "text http://example.com"
  8.       expected: "text <a href=\"http://example.com\">http://example.com</a>"
  9.  
  10.     - description: "Autolink url in mid-text"
  11.       text: "text http://example.com more text"
  12.       expected: "text <a href=\"http://example.com\">http://example.com</a> more text"
  13.  
  14.     - description: "Autolink url in Japanese text"
  15.       text: "いまなにしてるhttp://example.comいまなにしてる"
  16.       expected: "いまなにしてる<a href=\"http://example.com\">http://example.com</a>いまなにしてる"
  17.  
  18.     - description: "Autolink url surrounded by parentheses does not capture them"
  19.       text: "text (http://example.com)"
  20.       expected: "text (<a href=\"http://example.com\">http://example.com</a>)"
  21.  
  22.     - description: "Autolink url with path surrounded by parentheses does not capture them"
  23.       text: "text (http://example.com/test)"
  24.       expected: "text (<a href=\"http://example.com/test\">http://example.com/test</a>)"
  25.  
  26.     - description: "Autolink url with embedded parentheses"
  27.       text: "text http://msdn.com/S(deadbeef)/page.htm"
  28.       expected: "text <a href=\"http://msdn.com/S(deadbeef)/page.htm\">http://msdn.com/S(deadbeef)/page.htm</a>"
  29.  
  30.     - description: "Extract valid URL: http://msdn.microsoft.com/ja-jp/library/system.net.httpwebrequest(v=VS.100).aspx"
  31.       text: "text http://msdn.microsoft.com/ja-jp/library/system.net.httpwebrequest(v=VS.100).aspx"
  32.       expected: "text <a href=\"http://msdn.microsoft.com/ja-jp/library/system.net.httpwebrequest(v=VS.100).aspx\">http://msdn.microsoft.com/ja-jp/library/system.net.httpwebrequest(v=VS.100).aspx</a>"
  33.  
  34.     - description: "Autolink url with balanced parens hiding XSS"
  35.       text: 'text http://foo.com/("onclick="alert(1)")'
  36.       expected: 'text <a href="http://foo.com/">http://foo.com/</a>("onclick="alert(1)")'
  37.  
  38.     - description: "Autolink url should NOT capture unbalanced parens"
  39.       text: "Parenthetically bad http://example.com/i_has_a_) thing"
  40.       expected: "Parenthetically bad <a href=\"http://example.com/i_has_a_\">http://example.com/i_has_a_</a>) thing"
  41.  
  42.     - description: "Autolink url containing unicode characters"
  43.       text: "I enjoy Macintosh Brand computers: http://✪df.ws/ejp"
  44.       expected: "I enjoy Macintosh Brand computers: <a href=\"http://✪df.ws/ejp\">http://✪df.ws/ejp</a>"
  45.  
  46.     - description: "Autolink url with .co. under TLD"
  47.       text: "test http://www.example.co.jp"
  48.       expected: "test <a href=\"http://www.example.co.jp\">http://www.example.co.jp</a>"
  49.  
  50.     - description: "DO NOT Autolink url containing ! character in the domain"
  51.       text: "badly formatted http://foo!bar.com"
  52.       expected: "badly formatted http://foo!bar.com"
  53.  
  54.     - description: "DO NOT Autolink url containing _ character in the domain"
  55.       text: "badly formatted http://foo_bar.com"
  56.       expected: "badly formatted http://foo_bar.com"
  57.  
  58.     - description: "Autolink url preceded by :"
  59.       text: "text:http://example.com"
  60.       expected: "text:<a href=\"http://example.com\">http://example.com</a>"
  61.  
  62.     - description: "Autolink url followed by ? (without it)"
  63.       text: "text http://example.com?"
  64.       expected: "text <a href=\"http://example.com\">http://example.com</a>?"
  65.  
  66.     - description: "Autolink url followed by ! (without it)"
  67.       text: "text http://example.com!"
  68.       expected: "text <a href=\"http://example.com\">http://example.com</a>!"
  69.  
  70.     - description: "Autolink url followed by , (without it)"
  71.       text: "text http://example.com,"
  72.       expected: "text <a href=\"http://example.com\">http://example.com</a>,"
  73.  
  74.     - description: "Autolink url with path followed by a comma (wihout the comma)"
  75.       text: "In http://example.com/test, Douglas explains 42."
  76.       expected: "In <a href=\"http://example.com/test\">http://example.com/test</a>, Douglas explains 42."
  77.  
  78.     - description: "Autolink url followed by . (without it)"
  79.       text: "text http://example.com."
  80.       expected: "text <a href=\"http://example.com\">http://example.com</a>."
  81.  
  82.     - description: "Autolink url followed by : (without it)"
  83.       text: "text http://example.com:"
  84.       expected: "text <a href=\"http://example.com\">http://example.com</a>:"
  85.  
  86.     - description: "Autolink url followed by ; (without it)"
  87.       text: "text http://example.com;"
  88.       expected: "text <a href=\"http://example.com\">http://example.com</a>;"
  89.  
  90.     - description: "Autolink url followed by ] (without it)"
  91.       text: "text http://example.com]"
  92.       expected: "text <a href=\"http://example.com\">http://example.com</a>]"
  93.  
  94.     - description: "Autolink url followed by ) (without it)"
  95.       text: "text http://example.com)"
  96.       expected: "text <a href=\"http://example.com\">http://example.com</a>)"
  97.  
  98.     - description: "Autolink url followed by } (without it)"
  99.       text: "text http://example.com}"
  100.       expected: "text <a href=\"http://example.com\">http://example.com</a>}"
  101.  
  102.     - description: "Autolink url followed by = (without it)"
  103.       text: "text http://example.com="
  104.       expected: "text <a href=\"http://example.com\">http://example.com</a>="
  105.  
  106.     - description: "Autolink url followed by ' (without it)"
  107.       text: "text http://example.com'"
  108.       expected: "text <a href=\"http://example.com\">http://example.com</a>'"
  109.  
  110.     - description: "DO NOT Autolink url preceded by /"
  111.       text: "text /http://example.com"
  112.       expected: "text /http://example.com"
  113.  
  114.     - description: "DO NOT Autolink url preceded by !"
  115.       text: "text !http://example.com"
  116.       expected: "text !http://example.com"
  117.  
  118.     - description: "DO NOT Autolink url preceded by ="
  119.       text: "text =http://example.com"
  120.       expected: "text =http://example.com"
  121.  
  122.     - description: "DO NOT Autolink url preceded by @"
  123.       text: "@http://example.com"
  124.       expected: "@http://example.com"
  125.  
  126.     - description: "DO NOT Autolink domain in email address"
  127.       text: "[email protected]"
  128.       expected: "[email protected]"
  129.  
  130.     - description: "Autolink url embedded in link tag"
  131.       text: "<link rel='true'>http://example.com</link>"
  132.       expected: "<link rel='true'><a href=\"http://example.com\">http://example.com</a></link>"
  133.  
  134.     - description: "Autolink multiple urls"
  135.       text: "http://example.com https://sslexample.com http://sub.example.com"
  136.       expected: "<a href=\"http://example.com\">http://example.com</a> <a href=\"https://sslexample.com\">https://sslexample.com</a> <a href=\"http://sub.example.com\">http://sub.example.com</a>"
  137.  
  138.     - description: "Autolink url with long TLD"
  139.       text: "http://example.mobi/path"
  140.       expected: "<a href=\"http://example.mobi/path\">http://example.mobi/path</a>"
  141.  
  142.     - description: "Autolink url containing ending with #value (not as url + hashtag)"
  143.       text: "http://foo.com/?#foo"
  144.       expected: "<a href=\"http://foo.com/?#foo\">http://foo.com/?#foo</a>"
  145.  
  146.     - description: "DO NOT Autolink url without protocol (with www)"
  147.       text: "www.example.biz"
  148.       expected: "www.example.biz"
  149.  
  150.     - description: "DO NOT Autolink url without protocol (with WWW)"
  151.       text: "WWW.EXAMPLE.BIZ"
  152.       expected: "WWW.EXAMPLE.BIZ"
  153.  
  154.     - description: "DO NOT Autolink URL without protocol and without www (ending in .com)"
  155.       text: "foo.com"
  156.       expected: "foo.com"
  157.  
  158.     - description: "DO NOT Autolink URL without protocol and without www (ending in .org)"
  159.       text: "foo.org"
  160.       expected: "foo.org"
  161.  
  162.     - description: "DO NOT Autolink URL without protocol and without www (ending in .net)"
  163.       text: "foo.net"
  164.       expected: "foo.net"
  165.  
  166.     - description: "DO NOT Autolink URL without protocol and without www (ending in .gov)"
  167.       text: "foo.gov"
  168.       expected: "foo.gov"
  169.  
  170.     - description: "DO NOT Autolink URL without protocol and without www (ending in .edu)"
  171.       text: "foo.edu"
  172.       expected: "foo.edu"
  173.  
  174.     - description: "Autolink URL without protocol and without www not ending in /.(edu|com|gov|org|net)/"
  175.       text: "foo.it twitter.co.jp foo.commerce foo.nettastic foo.us foo.co.uk"
  176.       expected: "foo.it twitter.co.jp foo.commerce foo.nettastic foo.us foo.co.uk"
  177.  
  178.     - description: "Multiple URLs with different protocols but not without a protocol"
  179.       text:  "http://foo.com AND https://bar.com AND www.foobar.com"
  180.       expected: "<a href=\"http://foo.com\">http://foo.com</a> AND <a href=\"https://bar.com\">https://bar.com</a> AND www.foobar.com"
  181.  
  182.     - description: "Autolink raw domain followed by domain only links the first"
  183.       text: "See http://example.com example.com"
  184.       expected: "See <a href=\"http://example.com\">http://example.com</a> example.com"
  185.  
  186.     - description: "Autolink url that includes @-sign and numeric dir under it"
  187.       text: "http://www.flickr.com/photos/29674651@N00/4382024406"
  188.       expected: "<a href=\"http://www.flickr.com/photos/29674651@N00/4382024406\">http://www.flickr.com/photos/29674651@N00/4382024406</a>"
  189.  
  190.     - description: "Autolink url that includes @-sign and non-numeric dir under it"
  191.       text: "http://www.flickr.com/photos/29674651@N00/foobar"
  192.       expected: "<a href=\"http://www.flickr.com/photos/29674651@N00/foobar\">http://www.flickr.com/photos/29674651@N00/foobar</a>"
  193.  
  194.     - description: "Autolink URL with only a domain followed by a period doesn't swallow the period."
  195.       text: "I think it's proper to end sentences with a period http://tell.me.com. Even when they contain a URL."
  196.       expected: "I think it's proper to end sentences with a period <a href=\"http://tell.me.com\">http://tell.me.com</a>. Even when they contain a URL."
  197.  
  198.     - description: "Autolink URL with a path followed by a period doesn't swallow the period."
  199.       text: "I think it's proper to end sentences with a period http://tell.me/why. Even when they contain a URL."
  200.       expected: "I think it's proper to end sentences with a period <a href=\"http://tell.me/why\">http://tell.me/why</a>. Even when they contain a URL."
  201.  
  202.     - description: "Autolink URL with a query followed by a period doesn't swallow the period."
  203.       text: "I think it's proper to end sentences with a period http://tell.me/why?=because.i.want.it. Even when they contain a URL."
  204.       expected: "I think it's proper to end sentences with a period <a href=\"http://tell.me/why?=because.i.want.it\">http://tell.me/why?=because.i.want.it</a>. Even when they contain a URL."
  205.  
  206.     - description: "Autolink URL with a hyphen in the domain name"
  207.       text: "Czech out sweet deals at http://mrs.domain-dash.biz ok?"
  208.       expected: "Czech out sweet deals at <a href=\"http://mrs.domain-dash.biz\">http://mrs.domain-dash.biz</a> ok?"
  209.  
  210.     - description: "Autolink an IDN (punycode) domain and TLD"
  211.       text: "See also: http://xn--80abe5aohbnkjb.xn--p1ai/"
  212.       expected: "See also: <a href=\"http://xn--80abe5aohbnkjb.xn--p1ai/\">http://xn--80abe5aohbnkjb.xn--p1ai/</a>"
  213.  
  214.     - description: "Autolink URL should NOT autolink www...foo"
  215.       text: "Is www...foo a valid URL?"
  216.       expected: "Is www...foo a valid URL?"
  217.  
  218.     - description: "Autolink URL should NOT autolink www.-foo.com"
  219.       text: "Is www.-foo.com a valid URL?"
  220.       expected: "Is www.-foo.com a valid URL?"
  221.  
  222.     - description: "Autolink URL should NOT autolink a domain with a valid dash but no protocol"
  223.       text: "Is www.foo-bar.com a valid URL?"
  224.       expected: "Is www.foo-bar.com a valid URL?"
  225.  
  226.     - description: "Autolink URL should autolink a domain with a valid dash and a protocol"
  227.       text: "Is http://www.foo-bar.com a valid URL?"
  228.       expected: "Is <a href=\"http://www.foo-bar.com\">http://www.foo-bar.com</a> a valid URL?"
  229.  
  230.     - description: "Autolink URL should link search urls (with &lang=, not &lang;)"
  231.       text: "Check out http://search.twitter.com/search?q=avro&lang=en"
  232.       expected: "Check out <a href=\"http://search.twitter.com/search?q=avro&amp;lang=en\">http://search.twitter.com/search?q=avro&amp;lang=en</a>"
  233.  
  234.     - description: "Autolink URL should link urls with very long paths"
  235.       text: "Check out http://example.com/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</a>"
  237.  
  238.     - description: "Autolink URL should HTML escape the URL"
  239.       text: "example: http://twitter.com/otm_m@\"onmousedown=\"alert('foo')\" style=background-color:yellow;color:yellow;\"/"
  240.       expected: "example: <a href=\"http://twitter.com/otm_m\">http://twitter.com/otm_m</a>@\"onmousedown=\"alert('foo')\" style=background-color:yellow;color:yellow;\"/"
  241.  
  242.     - description: "Autolink URL should autolink a URL with a - or + at the end of the path"
  243.       text: "Go to http://example.com/a+ or http://example.com/a-"
  244.       expected: "Go to <a href=\"http://example.com/a+\">http://example.com/a+</a> or <a href=\"http://example.com/a-\">http://example.com/a-</a>"
  245.  
  246.     - description: "Autolink URL should autolink a URL with a - or + at the end of the path and query parameters"
  247.       text: "Go to http://example.com/a+?this=that or http://example.com/a-?this=that"
  248.       expected: "Go to <a href=\"http://example.com/a+?this=that\">http://example.com/a+?this=that</a> or <a href=\"http://example.com/a-?this=that\">http://example.com/a-?this=that</a>"
  249.  
  250.     - description: "Autolink URL should autolink URLs with longer paths ending in -"
  251.       text: "Go to http://example.com/view/slug-url-?foo=bar"
  252.       expected: "Go to <a href=\"http://example.com/view/slug-url-?foo=bar\">http://example.com/view/slug-url-?foo=bar</a>"
  253.  
  254.     - description: "Autolink URL should NOT link URLs with domains beginning in a space"
  255.       text: "@user Try http:// example.com/path"
  256.       expected: "@user Try http:// example.com/path"
  257.  
  258.     - description: "Autolink URL should NOT link URLs with domains beginning in a non-breaking space (U+00A0)"
  259.       text: "@user Try http:// example.com/path"
  260.       expected: "@user Try http:// example.com/path"
  261.  
  262.     - description: "Autolink URL should link paths containing accented characters"
  263.       text: "See: http://example.com/café"
  264.       expected: "See: <a href=\"http://example.com/café\">http://example.com/café</a>"
  265.  
  266.     - description: "Autolink URL should not link URL without protocol"
  267.       text: "See: www.twitter.com or twitter.com/twitter"
  268.       expected: "See: www.twitter.com or twitter.com/twitter"
  269.  
  270.   all:
  271.     - description: "Autolink all does not break on URL with @"
  272.       text: "http://www.flickr.com/photos/29674651@N00/4382024406 if you know what's good for you."
  273.       expected: "<a href=\"http://www.flickr.com/photos/29674651@N00/4382024406\">http://www.flickr.com/photos/29674651@N00/4382024406</a> if you know what's good for you."
  274.  
  275.     - description: "Autolink all does not allow & without ?"
  276.       text: "Check out: http://example.com/test&@chasesechrist"
  277.       expected: "Check out: <a href=\"http://example.com/test\">http://example.com/test</a>&@<a class=\"tweet-url username\" href=\"http://twitter.com/chasesechrist\">chasesechrist</a>"
  278.  
  279.     - description: "Correctly handles URL follower directly by @user"
  280.       text: "See: http://example.com/@user"
  281.       expected: "See: <a href=\"http://example.com/\">http://example.com/</a>@<a class=\"tweet-url username\" href=\"http://twitter.com/user\">user</a>"
  282.  
  283.     - description: "Correctly handles URL with an @user followed by trailing /"
  284.       text: "See: http://example.com/@user/"
  285.       expected: "See: <a href=\"http://example.com/@user/\">http://example.com/@user/</a>"
  286.  
  287.     - description: "Does not allow an XSS after an @"
  288.       text: "See: http://x.xx.com/@\"style=\"color:pink\"onmouseover=alert(1)//"
  289.       expected: "See: <a href=\"http://x.xx.com/\">http://x.xx.com/</a>@\"style=\"color:pink\"onmouseover=alert(1)//"
  290.  
  291.     - description: "DO NOT autolink URLs if preceded by # or @"
  292.       text: "#http://twitter.com @http://twitter.com"
  293.       expected: "#http://twitter.com @http://twitter.com"
  294.  
  295.     - description: "Autolink hashtag if followed by . and TLD"
  296.       text: "#twitter.com #twitter.co.jp"
  297.       expected: "<a href=\"http://twitter.com/search?q=%23twitter\" title=\"#twitter\" class=\"tweet-url hashtag\">#twitter</a>.com <a href=\"http://twitter.com/search?q=%23twitter\" title=\"#twitter\" class=\"tweet-url hashtag\">#twitter</a>.co.jp"
  298.  
  299.     - description: "Autolink @mention if followed by . and TLD"
  300.       text: "@twitter.com @twitter.co.jp"
  301.       expected: "@<a class=\"tweet-url username\" href=\"http://twitter.com/twitter\">twitter</a>.com @<a class=\"tweet-url username\" href=\"http://twitter.com/twitter\">twitter</a>.co.jp"