MakeClickable.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <?php
  2. /**
  3. * @group formatting
  4. */
  5. class Tests_Formatting_MakeClickable extends WP_UnitTestCase {
  6. function test_mailto_xss() {
  7. $in = 'testzzz@"STYLE="behavior:url(\'#default#time2\')"onBegin="alert(\'refresh-XSS\')"';
  8. $this->assertEquals($in, make_clickable($in));
  9. }
  10. function test_valid_mailto() {
  11. $valid_emails = array(
  12. 'foo@example.com',
  13. 'foo.bar@example.com',
  14. 'Foo.Bar@a.b.c.d.example.com',
  15. '0@example.com',
  16. 'foo@example-example.com',
  17. );
  18. foreach ($valid_emails as $email) {
  19. $this->assertEquals('<a href="mailto:'.$email.'">'.$email.'</a>', make_clickable($email));
  20. }
  21. }
  22. function test_invalid_mailto() {
  23. $invalid_emails = array(
  24. 'foo',
  25. 'foo@',
  26. 'foo@@example.com',
  27. '@example.com',
  28. 'foo @example.com',
  29. 'foo@example',
  30. );
  31. foreach ($invalid_emails as $email) {
  32. $this->assertEquals($email, make_clickable($email));
  33. }
  34. }
  35. // tests that make_clickable will not link trailing periods, commas and
  36. // (semi-)colons in URLs with protocol (i.e. http://wordpress.org)
  37. function test_strip_trailing_with_protocol() {
  38. $urls_before = array(
  39. 'http://wordpress.org/hello.html',
  40. 'There was a spoon named http://wordpress.org. Alice!',
  41. 'There was a spoon named http://wordpress.org, said Alice.',
  42. 'There was a spoon named http://wordpress.org; said Alice.',
  43. 'There was a spoon named http://wordpress.org: said Alice.',
  44. 'There was a spoon named (http://wordpress.org) said Alice.'
  45. );
  46. $urls_expected = array(
  47. '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>',
  48. 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>. Alice!',
  49. 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>, said Alice.',
  50. 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>; said Alice.',
  51. 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>: said Alice.',
  52. 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>) said Alice.'
  53. );
  54. foreach ($urls_before as $key => $url) {
  55. $this->assertEquals($urls_expected[$key], make_clickable($url));
  56. }
  57. }
  58. // tests that make_clickable will not link trailing periods, commas and
  59. // (semi-)colons in URLs with protocol (i.e. http://wordpress.org)
  60. function test_strip_trailing_with_protocol_nothing_afterwards() {
  61. $urls_before = array(
  62. 'http://wordpress.org/hello.html',
  63. 'There was a spoon named http://wordpress.org.',
  64. 'There was a spoon named http://wordpress.org,',
  65. 'There was a spoon named http://wordpress.org;',
  66. 'There was a spoon named http://wordpress.org:',
  67. 'There was a spoon named (http://wordpress.org)',
  68. 'There was a spoon named (http://wordpress.org)x',
  69. );
  70. $urls_expected = array(
  71. '<a href="http://wordpress.org/hello.html" rel="nofollow">http://wordpress.org/hello.html</a>',
  72. 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>.',
  73. 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>,',
  74. 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>;',
  75. 'There was a spoon named <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>:',
  76. 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)',
  77. 'There was a spoon named (<a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>)x',
  78. );
  79. foreach ($urls_before as $key => $url) {
  80. $this->assertEquals($urls_expected[$key], make_clickable($url));
  81. }
  82. }
  83. // tests that make_clickable will not link trailing periods, commas and
  84. // (semi-)colons in URLs without protocol (i.e. www.wordpress.org)
  85. function test_strip_trailing_without_protocol() {
  86. $urls_before = array(
  87. 'www.wordpress.org',
  88. 'There was a spoon named www.wordpress.org. Alice!',
  89. 'There was a spoon named www.wordpress.org, said Alice.',
  90. 'There was a spoon named www.wordpress.org; said Alice.',
  91. 'There was a spoon named www.wordpress.org: said Alice.',
  92. 'There was a spoon named www.wordpress.org) said Alice.'
  93. );
  94. $urls_expected = array(
  95. '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
  96. 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>. Alice!',
  97. 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>, said Alice.',
  98. 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>; said Alice.',
  99. 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>: said Alice.',
  100. 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>) said Alice.'
  101. );
  102. foreach ($urls_before as $key => $url) {
  103. $this->assertEquals($urls_expected[$key], make_clickable($url));
  104. }
  105. }
  106. // tests that make_clickable will not link trailing periods, commas and
  107. // (semi-)colons in URLs without protocol (i.e. www.wordpress.org)
  108. function test_strip_trailing_without_protocol_nothing_afterwards() {
  109. $urls_before = array(
  110. 'www.wordpress.org',
  111. 'There was a spoon named www.wordpress.org.',
  112. 'There was a spoon named www.wordpress.org,',
  113. 'There was a spoon named www.wordpress.org;',
  114. 'There was a spoon named www.wordpress.org:',
  115. 'There was a spoon named www.wordpress.org)'
  116. );
  117. $urls_expected = array(
  118. '<a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>',
  119. 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>.',
  120. 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>,',
  121. 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>;',
  122. 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>:',
  123. 'There was a spoon named <a href="http://www.wordpress.org" rel="nofollow">http://www.wordpress.org</a>)'
  124. );
  125. foreach ($urls_before as $key => $url) {
  126. $this->assertEquals($urls_expected[$key], make_clickable($url));
  127. }
  128. }
  129. // #4570
  130. function test_iri() {
  131. $urls_before = array(
  132. 'http://www.詹姆斯.com/',
  133. 'http://bg.wikipedia.org/Баба',
  134. 'http://example.com/?a=баба&b=дядо',
  135. );
  136. $urls_expected = array(
  137. '<a href="http://www.詹姆斯.com/" rel="nofollow">http://www.詹姆斯.com/</a>',
  138. '<a href="http://bg.wikipedia.org/Баба" rel="nofollow">http://bg.wikipedia.org/Баба</a>',
  139. '<a href="http://example.com/?a=баба&#038;b=дядо" rel="nofollow">http://example.com/?a=баба&#038;b=дядо</a>',
  140. );
  141. foreach ($urls_before as $key => $url) {
  142. $this->assertEquals($urls_expected[$key], make_clickable($url));
  143. }
  144. }
  145. // #10990
  146. function test_brackets_in_urls() {
  147. $urls_before = array(
  148. 'http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)',
  149. '(http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software))',
  150. 'blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah',
  151. 'blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah',
  152. 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software) blah blah',
  153. 'blah blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah',
  154. 'blah blah (http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)) blah blah',
  155. 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).) blah blah',
  156. 'blah blah http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software).)moreurl blah blah',
  157. 'In his famous speech “You and Your research” (here:
  158. http://www.cs.virginia.edu/~robins/YouAndYourResearch.html)
  159. Richard Hamming wrote about people getting more done with their doors closed, but',
  160. );
  161. $urls_expected = array(
  162. '<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>',
  163. '(<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>)',
  164. 'blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a> blah',
  165. 'blah (<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>) blah',
  166. 'blah blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a> blah blah',
  167. 'blah blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>) blah blah',
  168. 'blah blah (<a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>) blah blah',
  169. 'blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>.) blah blah',
  170. 'blah blah <a href="http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)" rel="nofollow">http://en.wikipedia.org/wiki/PC_Tools_(Central_Point_Software)</a>.)moreurl blah blah',
  171. 'In his famous speech “You and Your research” (here:
  172. <a href="http://www.cs.virginia.edu/~robins/YouAndYourResearch.html" rel="nofollow">http://www.cs.virginia.edu/~robins/YouAndYourResearch.html</a>)
  173. Richard Hamming wrote about people getting more done with their doors closed, but',
  174. );
  175. foreach ($urls_before as $key => $url) {
  176. $this->assertEquals($urls_expected[$key], make_clickable($url));
  177. }
  178. }
  179. // Based on a real comments which were incorrectly linked. #11211
  180. function test_real_world_examples() {
  181. $urls_before = array(
  182. 'Example: WordPress, test (some text), I love example.com (http://example.org), it is brilliant',
  183. 'Example: WordPress, test (some text), I love example.com (http://example.com), it is brilliant',
  184. 'Some text followed by a bracketed link with a trailing elipsis (http://example.com)...',
  185. 'In his famous speech “You and Your research” (here: http://www.cs.virginia.edu/~robins/YouAndYourResearch.html) Richard Hamming wrote about people getting more done with their doors closed...',
  186. );
  187. $urls_expected = array(
  188. 'Example: WordPress, test (some text), I love example.com (<a href="http://example.org" rel="nofollow">http://example.org</a>), it is brilliant',
  189. 'Example: WordPress, test (some text), I love example.com (<a href="http://example.com" rel="nofollow">http://example.com</a>), it is brilliant',
  190. 'Some text followed by a bracketed link with a trailing elipsis (<a href="http://example.com" rel="nofollow">http://example.com</a>)...',
  191. 'In his famous speech “You and Your research” (here: <a href="http://www.cs.virginia.edu/~robins/YouAndYourResearch.html" rel="nofollow">http://www.cs.virginia.edu/~robins/YouAndYourResearch.html</a>) Richard Hamming wrote about people getting more done with their doors closed...',
  192. );
  193. foreach ($urls_before as $key => $url) {
  194. $this->assertEquals($urls_expected[$key], make_clickable($url));
  195. }
  196. }
  197. // #14993
  198. function test_twitter_hash_bang() {
  199. $urls_before = array(
  200. 'http://twitter.com/#!/wordpress/status/25907440233',
  201. 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233 !',
  202. 'This is a really good tweet http://twitter.com/#!/wordpress/status/25907440233!',
  203. );
  204. $urls_expected = array(
  205. '<a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>',
  206. 'This is a really good tweet <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a> !',
  207. 'This is a really good tweet <a href="http://twitter.com/#!/wordpress/status/25907440233" rel="nofollow">http://twitter.com/#!/wordpress/status/25907440233</a>!',
  208. );
  209. foreach ($urls_before as $key => $url) {
  210. $this->assertEquals($urls_expected[$key], make_clickable($url));
  211. }
  212. }
  213. function test_wrapped_in_angles() {
  214. $before = array(
  215. 'URL wrapped in angle brackets <http://example.com/>',
  216. 'URL wrapped in angle brackets with padding < http://example.com/ >',
  217. 'mailto wrapped in angle brackets <foo@example.com>',
  218. );
  219. $expected = array(
  220. 'URL wrapped in angle brackets <<a href="http://example.com/" rel="nofollow">http://example.com/</a>>',
  221. 'URL wrapped in angle brackets with padding < <a href="http://example.com/" rel="nofollow">http://example.com/</a> >',
  222. 'mailto wrapped in angle brackets <foo@example.com>',
  223. );
  224. foreach ($before as $key => $url) {
  225. $this->assertEquals($expected[$key], make_clickable($url));
  226. }
  227. }
  228. function test_preceded_by_punctuation() {
  229. $before = array(
  230. 'Comma then URL,http://example.com/',
  231. 'Period then URL.http://example.com/',
  232. 'Semi-colon then URL;http://example.com/',
  233. 'Colon then URL:http://example.com/',
  234. 'Exclamation mark then URL!http://example.com/',
  235. 'Question mark then URL?http://example.com/',
  236. );
  237. $expected = array(
  238. 'Comma then URL,<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
  239. 'Period then URL.<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
  240. 'Semi-colon then URL;<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
  241. 'Colon then URL:<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
  242. 'Exclamation mark then URL!<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
  243. 'Question mark then URL?<a href="http://example.com/" rel="nofollow">http://example.com/</a>',
  244. );
  245. foreach ($before as $key => $url) {
  246. $this->assertEquals($expected[$key], make_clickable($url));
  247. }
  248. }
  249. function test_dont_break_attributes() {
  250. $urls_before = array(
  251. "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>",
  252. "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
  253. "http://trunk.domain/testing#something (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
  254. "http://trunk.domain/testing#something
  255. (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
  256. "<span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/nd_BdvG43rE&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' /> <param name='allowfullscreen' value='true' /> <param name='wmode' value='opaque' /> <embed src='http://www.youtube.com/v/nd_BdvG43rE&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' type='application/x-shockwave-flash' allowfullscreen='true' width='425' height='350' wmode='opaque'></embed> </object></span>",
  257. '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
  258. );
  259. $urls_expected = array(
  260. "<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>",
  261. "(<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
  262. "<a href=\"http://trunk.domain/testing#something\" rel=\"nofollow\">http://trunk.domain/testing#something</a> (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
  263. "<a href=\"http://trunk.domain/testing#something\" rel=\"nofollow\">http://trunk.domain/testing#something</a>
  264. (<img src='http://trunk.domain/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley'>)",
  265. "<span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/nd_BdvG43rE&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' /> <param name='allowfullscreen' value='true' /> <param name='wmode' value='opaque' /> <embed src='http://www.youtube.com/v/nd_BdvG43rE&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1' type='application/x-shockwave-flash' allowfullscreen='true' width='425' height='350' wmode='opaque'></embed> </object></span>",
  266. '<a href="http://example.com/example.gif" title="Image from http://example.com">Look at this image!</a>',
  267. );
  268. foreach ($urls_before as $key => $url) {
  269. $this->assertEquals($urls_expected[$key], make_clickable($url));
  270. }
  271. }
  272. /**
  273. * @ticket 23756
  274. */
  275. function test_no_links_inside_pre_or_code() {
  276. $before = array(
  277. '<pre>http://wordpress.org</pre>',
  278. '<code>http://wordpress.org</code>',
  279. '<pre class="foobar" id="foo">http://wordpress.org</pre>',
  280. '<code class="foobar" id="foo">http://wordpress.org</code>',
  281. '<precustomtag>http://wordpress.org</precustomtag>',
  282. '<codecustomtag>http://wordpress.org</codecustomtag>',
  283. 'URL before pre http://wordpress.org<pre>http://wordpress.org</pre>',
  284. 'URL before code http://wordpress.org<code>http://wordpress.org</code>',
  285. 'URL after pre <PRE>http://wordpress.org</PRE>http://wordpress.org',
  286. 'URL after code <code>http://wordpress.org</code>http://wordpress.org',
  287. 'URL before and after pre http://wordpress.org<pre>http://wordpress.org</pre>http://wordpress.org',
  288. 'URL before and after code http://wordpress.org<code>http://wordpress.org</code>http://wordpress.org',
  289. 'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>',
  290. );
  291. $expected = array(
  292. '<pre>http://wordpress.org</pre>',
  293. '<code>http://wordpress.org</code>',
  294. '<pre class="foobar" id="foo">http://wordpress.org</pre>',
  295. '<code class="foobar" id="foo">http://wordpress.org</code>',
  296. '<precustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></precustomtag>',
  297. '<codecustomtag><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a></codecustomtag>',
  298. 'URL before pre <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><pre>http://wordpress.org</pre>',
  299. 'URL before code <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><code>http://wordpress.org</code>',
  300. 'URL after pre <PRE>http://wordpress.org</PRE><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
  301. 'URL after code <code>http://wordpress.org</code><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
  302. 'URL before and after pre <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><pre>http://wordpress.org</pre><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
  303. 'URL before and after code <a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a><code>http://wordpress.org</code><a href="http://wordpress.org" rel="nofollow">http://wordpress.org</a>',
  304. 'code inside pre <pre>http://wordpress.org <code>http://wordpress.org</code> http://wordpress.org</pre>',
  305. );
  306. foreach ( $before as $key => $url )
  307. $this->assertEquals( $expected[ $key ], make_clickable( $url ) );
  308. }
  309. /**
  310. * @ticket 16892
  311. */
  312. function test_click_inside_html() {
  313. $urls_before = array(
  314. '<span>http://example.com</span>',
  315. '<p>http://example.com/</p>',
  316. );
  317. $urls_expected = array(
  318. '<span><a href="http://example.com" rel="nofollow">http://example.com</a></span>',
  319. '<p><a href="http://example.com/" rel="nofollow">http://example.com/</a></p>',
  320. );
  321. foreach ($urls_before as $key => $url) {
  322. $this->assertEquals( $urls_expected[$key], make_clickable( $url ) );
  323. }
  324. }
  325. function test_no_links_within_links() {
  326. $in = array(
  327. 'Some text with a link <a href="http://example.com">http://example.com</a>',
  328. //'<a href="http://wordpress.org">This is already a link www.wordpress.org</a>', // fails in 3.3.1 too
  329. );
  330. foreach ( $in as $text ) {
  331. $this->assertEquals( $text, make_clickable( $text ) );
  332. }
  333. }
  334. /**
  335. * @ticket 16892
  336. */
  337. function test_no_segfault() {
  338. $in = str_repeat( 'http://example.com/2011/03/18/post-title/', 256 );
  339. $out = make_clickable( $in );
  340. $this->assertEquals( $in, $out );
  341. }
  342. /**
  343. * @ticket 16859
  344. */
  345. function test_square_brackets() {
  346. $urls_before = array(
  347. 'http://example.com/?foo[bar]=baz',
  348. 'http://example.com/?baz=bar&foo[bar]=baz',
  349. );
  350. $urls_expected = array(
  351. '<a href="http://example.com/?foo%5Bbar%5D=baz" rel="nofollow">http://example.com/?foo%5Bbar%5D=baz</a>',
  352. '<a href="http://example.com/?baz=bar&#038;foo%5Bbar%5D=baz" rel="nofollow">http://example.com/?baz=bar&#038;foo%5Bbar%5D=baz</a>',
  353. );
  354. foreach ($urls_before as $key => $url) {
  355. $this->assertEquals( $urls_expected[$key], make_clickable( $url ) );
  356. }
  357. }
  358. /**
  359. * @ticket 19028
  360. */
  361. function test_line_break_in_existing_clickable_link() {
  362. $html = "<a
  363. href='mailto:someone@example.com'>someone@example.com</a>";
  364. $this->assertEquals( $html, make_clickable( $html ) );
  365. }
  366. }