[1] | 1 | <?php |
---|
| 2 | /** |
---|
[362] | 3 | * The Strangecode Codebase - a general application development framework for PHP |
---|
| 4 | * For details visit the project site: <http://trac.strangecode.com/codebase/> |
---|
[396] | 5 | * Copyright 2001-2012 Strangecode, LLC |
---|
[541] | 6 | * |
---|
[362] | 7 | * This file is part of The Strangecode Codebase. |
---|
[42] | 8 | * |
---|
[362] | 9 | * The Strangecode Codebase is free software: you can redistribute it and/or |
---|
| 10 | * modify it under the terms of the GNU General Public License as published by the |
---|
| 11 | * Free Software Foundation, either version 3 of the License, or (at your option) |
---|
| 12 | * any later version. |
---|
[541] | 13 | * |
---|
[362] | 14 | * The Strangecode Codebase is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
| 17 | * details. |
---|
[541] | 18 | * |
---|
[362] | 19 | * You should have received a copy of the GNU General Public License along with |
---|
| 20 | * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | /** |
---|
| 24 | * PHPUnit test case for codebase/lib/Utilities.inc.php |
---|
| 25 | * |
---|
[42] | 26 | * The method skeletons below need to be filled in with |
---|
| 27 | * real data so that the tests will run correctly. Replace |
---|
| 28 | * all EXPECTED_VAL and PARAM strings with real data. |
---|
| 29 | * |
---|
[1] | 30 | * Created with PHPUnit_Skeleton on 2005-08-09 |
---|
| 31 | */ |
---|
| 32 | |
---|
[468] | 33 | class UtilitiesTest extends PHPUnit_Framework_TestCase { |
---|
| 34 | |
---|
[1] | 35 | function setUp() |
---|
| 36 | { |
---|
[541] | 37 | define('_CLI', true); |
---|
[1] | 38 | require dirname(__FILE__) . '/_config.inc.php'; |
---|
| 39 | require_once '../lib/Utilities.inc.php'; |
---|
[541] | 40 | // $this->Utilities =& new Utilities(PARAM); |
---|
[1] | 41 | } |
---|
| 42 | |
---|
| 43 | function tearDown() |
---|
| 44 | { |
---|
[541] | 45 | $app =& App::getInstance(); |
---|
| 46 | $app->stop(); |
---|
[1] | 47 | } |
---|
| 48 | |
---|
[541] | 49 | function test_hyperlinkTxt() |
---|
| 50 | { |
---|
| 51 | $urls = [ |
---|
[545] | 52 | ' http://www.asdf.com/ ' => ' <a href="http://www.asdf.com/">www.asdf.com</a> ', |
---|
| 53 | ' ws://www.asdf.com/ ' => ' <a href="ws://www.asdf.com/">ws://www.asdf.com/</a> ', |
---|
| 54 | ' sftp://user@host.tld:22/path/x ' => ' <a href="sftp://user@host.tld:22/path/x">sftp://user@host.tld:22/path/x</a> ', |
---|
| 55 | ' www.asdf.com/ ' => ' <a href="http://www.asdf.com/">www.asdf.com</a> ', |
---|
| 56 | ' http://asdf/ ' => ' <a href="http://asdf/">asdf</a> ', |
---|
| 57 | ' www.asdf.com/? ' => ' <a href="http://www.asdf.com/">www.asdf.com</a>? ', |
---|
[541] | 58 | ' www.asdf.com/?x=y+z ' => ' <a href="http://www.asdf.com/?x=y+z">www.asdf.com/?x=y+z</a> ', |
---|
| 59 | ' www.asdf.com/?x=y+ ' => ' <a href="http://www.asdf.com/?x=y+">www.asdf.com/?x=y+</a> ', |
---|
| 60 | ' www.asdf.com/?x= ' => ' <a href="http://www.asdf.com/?x=">www.asdf.com/?x=</a> ', |
---|
| 61 | ' www.asdf.com/?x ' => ' <a href="http://www.asdf.com/?x">www.asdf.com/?x</a> ', |
---|
| 62 | ' www.asdf.com/?â€ïž=ð¥ ' => ' <a href="http://www.asdf.com/?â€ïž=ð¥">www.asdf.com/?â€ïž=ð¥</a> ', |
---|
| 63 | ' www.asdf.com? ' => ' <a href="http://www.asdf.com">www.asdf.com</a>? ', |
---|
| 64 | ' www.asdf.com! ' => ' <a href="http://www.asdf.com">www.asdf.com</a>! ', |
---|
| 65 | ' www.asdf.com. ' => ' <a href="http://www.asdf.com">www.asdf.com</a>. ', |
---|
| 66 | ' `www.asdf.com` ' => ' `www.asdf.com` ', |
---|
| 67 | ' "www.asdf.com" ' => ' "www.asdf.com" ', |
---|
| 68 | ' <www.asdf.com> ' => ' <<a href="http://www.asdf.com">www.asdf.com</a>> ', |
---|
| 69 | ' <http://www.asdf.com> ' => ' <<a href="http://www.asdf.com">www.asdf.com</a>> ', |
---|
| 70 | ' (http://www.asdf.com) ' => ' (<a href="http://www.asdf.com">www.asdf.com</a>) ', |
---|
| 71 | ' (URL: http://www.asdf.com#1) ' => ' (URL: <a href="http://www.asdf.com#1">www.asdf.com#1</a>) ', |
---|
| 72 | ' <a href="http://www.example.com/">Click Here</a> ' => ' <a href="http://www.example.com/">Click Here</a> ', |
---|
| 73 | ' <a href="http://www.example.com/">http://www.example.com/</a> ' => ' <a href="http://www.example.com/">http://www.example.com/</a> ', |
---|
| 74 | ' <a href=http://www.example.com/>http://www.example.com/</a> ' => ' <a href=http://www.example.com/>http://www.example.com/</a> ', |
---|
| 75 | ' <a href=\'http://www.example.com/\' >http://www.example.com/</a> ' => ' <a href=\'http://www.example.com/\' >http://www.example.com/</a> ', |
---|
| 76 | ' http://foo.com/blah_blah ' => ' <a href="http://foo.com/blah_blah">foo.com/blah_blah</a> ', |
---|
| 77 | ' http://foo.com/blah_blah/ ' => ' <a href="http://foo.com/blah_blah/">foo.com/blah_blah/</a> ', |
---|
| 78 | ' http://foo.com/blah_blah_(wikipedia) ' => ' <a href="http://foo.com/blah_blah_(wikipedia">foo.com/blah_blah_(wikipedia</a>) ', |
---|
| 79 | ' http://foo.com/blah_blah_(wikipedia)_(again) ' => ' <a href="http://foo.com/blah_blah_(wikipedia)_(again">foo.com/blah_blah_(wikipedia)_(again</a>) ', |
---|
| 80 | ' http://www.example.com/wpstyle/?p=364 ' => ' <a href="http://www.example.com/wpstyle/?p=364">www.example.com/wpstyle/?p=364</a> ', |
---|
| 81 | ' https://www.example.com/foo/?bar=baz&inga=42&quux ' => ' <a href="https://www.example.com/foo/?bar=baz&inga=42&quux">www.example.com/foo/?bar=baz&inga=42&quux</a> ', |
---|
| 82 | ' http://âªdf.ws/123 ' => ' <a href="http://âªdf.ws/123">âªdf.ws/123</a> ', |
---|
| 83 | ' http://userid:password@example.com:8080 ' => ' <a href="http://userid:password@example.com:8080">userid:password@example.com:8080</a> ', |
---|
[545] | 84 | ' http://userid:password@example.com:8080/ ' => ' <a href="http://userid:password@example.com:8080/">userid:password@example.com:8080</a> ', |
---|
[541] | 85 | ' http://userid@example.com ' => ' <a href="http://userid@example.com">userid@example.com</a> ', |
---|
[545] | 86 | ' http://userid@example.com/ ' => ' <a href="http://userid@example.com/">userid@example.com</a> ', |
---|
[541] | 87 | ' http://userid@example.com:8080 ' => ' <a href="http://userid@example.com:8080">userid@example.com:8080</a> ', |
---|
[545] | 88 | ' http://userid@example.com:8080/ ' => ' <a href="http://userid@example.com:8080/">userid@example.com:8080</a> ', |
---|
[541] | 89 | ' http://userid:password@example.com ' => ' <a href="http://userid:password@example.com">userid:password@example.com</a> ', |
---|
[545] | 90 | ' http://userid:password@example.com/ ' => ' <a href="http://userid:password@example.com/">userid:password@example.com</a> ', |
---|
| 91 | ' http://142.42.1.1/ ' => ' <a href="http://142.42.1.1/">142.42.1.1</a> ', |
---|
| 92 | ' http://142.42.1.1:8080/ ' => ' <a href="http://142.42.1.1:8080/">142.42.1.1:8080</a> ', |
---|
[541] | 93 | ' http://â¡.ws/äš¹ ' => ' <a href="http://â¡.ws/äš¹">â¡.ws/äš¹</a> ', |
---|
| 94 | ' http://â.ws ' => ' <a href="http://â.ws">â.ws</a> ', |
---|
[545] | 95 | ' http://â.ws/ ' => ' <a href="http://â.ws/">â.ws</a> ', |
---|
[541] | 96 | ' http://foo.com/blah_(wikipedia)#cite-1 ' => ' <a href="http://foo.com/blah_(wikipedia)#cite-1">foo.com/blah_(wikipedia)#cite-1</a> ', |
---|
| 97 | ' http://foo.com/blah_(wikipedia)_blah#cite-1 ' => ' <a href="http://foo.com/blah_(wikipedia)_blah#cite-1">foo.com/blah_(wikipedia)_blah#cite-1</a> ', |
---|
| 98 | ' http://foo.com/unicode_(âª)_in_parens ' => ' <a href="http://foo.com/unicode_(âª)_in_parens">foo.com/unicode_(âª)_in_parens</a> ', |
---|
| 99 | ' http://foo.com/(something)?after=parens ' => ' <a href="http://foo.com/(something)?after=parens">foo.com/(something)?after=parens</a> ', |
---|
[545] | 100 | ' http://âº.damowmow.com/ ' => ' <a href="http://âº.damowmow.com/">âº.damowmow.com</a> ', |
---|
[541] | 101 | ' http://code.google.com/events/#&product=browser ' => ' <a href="http://code.google.com/events/#&product=browser">code.google.com/events/#&product=browser</a> ', |
---|
| 102 | ' http://j.mp ' => ' <a href="http://j.mp">j.mp</a> ', |
---|
[545] | 103 | ' ftp://foo.bar/baz ' => ' <a href="ftp://foo.bar/baz">ftp://foo.bar/baz</a> ', |
---|
[541] | 104 | ' http://foo.bar/?q=Test%20URL-encoded%20stuff ' => ' <a href="http://foo.bar/?q=Test%20URL-encoded%20stuff">foo.bar/?q=Test%20URL-encoded%20stuff</a> ', |
---|
| 105 | ' http://Ù
ثاÙ.إختؚار ' => ' <a href="http://Ù
ثاÙ.إختؚار">Ù
ثاÙ.إختؚار</a> ', |
---|
| 106 | ' http://äŸå.æµè¯ ' => ' <a href="http://äŸå.æµè¯">äŸå.æµè¯</a> ', |
---|
| 107 | ' http://à€à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥à€à¥à€·à€Ÿ ' => ' <a href="http://à€à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥à€à¥à€·à€Ÿ">à€à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥à€à¥à€·à€Ÿ</a> ', |
---|
| 108 | ' http://-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com ' => ' <a href="http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com">-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com</a> ', |
---|
| 109 | ' http://1337.net ' => ' <a href="http://1337.net">1337.net</a> ', |
---|
| 110 | ' http://a.b-c.de ' => ' <a href="http://a.b-c.de">a.b-c.de</a> ', |
---|
| 111 | ' http://223.255.255.254 ' => ' <a href="http://223.255.255.254">223.255.255.254</a> ', |
---|
| 112 | ' http://x and.co OK?' => ' http://x and.co OK?', |
---|
| 113 | ' http://foo.bar?q=Spaces should be encoded ' => ' <a href="http://foo.bar?q=Spaces">foo.bar?q=Spaces</a> should be encoded ', |
---|
| 114 | ' https://github.com/search?utf8=â&q=gif ' => ' <a href="https://github.com/search?utf8=â&q=gif">github.com/search?utf8=â&q=gif</a> ', |
---|
| 115 | ' https://github.com/search?q=gif&utf8=* ' => ' <a href="https://github.com/search?q=gif&utf8=*">github.com/search?q=gif&utf8=*</a> ', |
---|
| 116 | ' https://github.com/search?q=gif&utf8=â ' => ' <a href="https://github.com/search?q=gif&utf8=â">github.com/search?q=gif&utf8=â</a> ', |
---|
| 117 | |
---|
[545] | 118 | // These should fail. |
---|
| 119 | ' http://x and.co OK?' => ' http://x and.co OK?', |
---|
| 120 | ' www. ' => ' www. ', |
---|
| 121 | ' www.x ' => ' www.x ', |
---|
| 122 | ' http: ' => ' http: ', |
---|
| 123 | ' http:// ' => ' http:// ', |
---|
| 124 | ' http:x ' => ' http:x ', |
---|
| 125 | ' http://x ' => ' http://x ', |
---|
| 126 | ' http://x/ ' => ' http://x/ ', |
---|
| 127 | ' http:// ?.x.com/ ' => ' http:// ?.x.com/ ', |
---|
| 128 | ' http://?.com/ ' => ' http://?.com/ ', |
---|
| 129 | ' http://.?.com/ ' => ' http://.?.com/ ', |
---|
| 130 | |
---|
[541] | 131 | // These are allowed to fuckup due to limitations in our ability to be omnipotent. |
---|
[545] | 132 | ' http:// www.x.com/ ' => ' http:// <a href="http://www.x.com/">www.x.com</a> ', |
---|
| 133 | ' <a href=http://www.example.com/ > http://www.example.com/</a> ' => ' <a href=http://www.example.com/ > <a href="http://www.example.com/">www.example.com</a></a> ', |
---|
| 134 | |
---|
| 135 | '<a href="http://www.example.com">Lorem ipsum</a> <a href="sftp://user@host.tld/path">dolor sit amet</a> sftp://user@host.tld/path, [http://www.example.com/ consetetur] sadipscing elitr, (sed diam) www.example.com! Nonumy http://x.com! Invidunt mailto:asdf@asdf.com ut <a href="mailto:asdf@asdf.com">asdf@asdf.com</a> \'\'\'et dolore\'\'\' magna. <!-- comment --> Aliquyam:erat, sed://diam //voluptua//. At vero.eos.et {{{ for (var i = Things.length - 1; i >= 0; i--) { Things[i]; } }}} `http://x.com` justo duo doloreshttp://www.not.com!' => '<a href="http://www.example.com">Lorem ipsum</a> <a href="sftp://user@host.tld/path">dolor sit amet</a> <a href="sftp://user@host.tld/path">sftp://user@host.tld/path</a>, [<a href="http://www.example.com/">www.example.com</a> consetetur] sadipscing elitr, (sed diam) <a href="http://www.example.com">www.example.com</a>! Nonumy <a href="http://x.com">x.com</a>! Invidunt <a href="mailto:asdf@asdf.com">mailto:asdf@asdf.com</a> ut <a href="mailto:asdf@asdf.com">asdf@asdf.com</a> \'\'\'et dolore\'\'\' magna. <!-- comment --> Aliquyam:erat, <a href="sed://diam">sed://diam</a> //voluptua//. At vero.eos.et {{{ for (var i = Things.length - 1; i >= 0; i--) { Things[i]; } }}} `http://x.com` justo duo <a href="doloreshttp://www.not.com">doloreshttp://www.not.com</a>!', |
---|
[541] | 136 | ]; |
---|
[545] | 137 | |
---|
| 138 | $urls_strict = [ |
---|
| 139 | ' http://www.asdf.com/ ' => ' <a href="http://www.asdf.com/">www.asdf.com</a> ', |
---|
| 140 | ' ws://www.asdf.com/ ' => ' <a href="ws://www.asdf.com/">ws://www.asdf.com/</a> ', |
---|
| 141 | ' sftp://user@host.tld:22/path/x ' => ' <a href="sftp://user@host.tld:22/path/x">sftp://user@host.tld:22/path/x</a> ', |
---|
| 142 | ' sip:beer ' => ' <a href="sip:beer">sip:beer</a> ', |
---|
| 143 | ' http://asdf/ ' => ' <a href="http://asdf/">asdf</a> ', |
---|
| 144 | ' http://www.asdf.com/? ' => ' <a href="http://www.asdf.com/?">www.asdf.com/?</a> ', |
---|
| 145 | ' http://www.asdf.com/?x=y+z ' => ' <a href="http://www.asdf.com/?x=y+z">www.asdf.com/?x=y+z</a> ', |
---|
| 146 | ' http://www.asdf.com/?x=y+ ' => ' <a href="http://www.asdf.com/?x=y+">www.asdf.com/?x=y+</a> ', |
---|
| 147 | ' http://www.asdf.com/?x= ' => ' <a href="http://www.asdf.com/?x=">www.asdf.com/?x=</a> ', |
---|
| 148 | ' http://www.asdf.com/?x ' => ' <a href="http://www.asdf.com/?x">www.asdf.com/?x</a> ', |
---|
| 149 | ' https://www.asdf.com/?â€ïž=ð¥ ' => ' <a href="https://www.asdf.com/?â€ïž=ð¥">www.asdf.com/?â€ïž=ð¥</a> ', |
---|
| 150 | ' www.asdf.com? ' => ' www.asdf.com? ', |
---|
| 151 | ' www.asdf.com/ ' => ' www.asdf.com/ ', |
---|
| 152 | ' www.asdf.com/? ' => ' www.asdf.com/? ', |
---|
| 153 | ' www.asdf.com/?x=y+z ' => ' www.asdf.com/?x=y+z ', |
---|
| 154 | ' www.asdf.com/?x=y+ ' => ' www.asdf.com/?x=y+ ', |
---|
| 155 | ' www.asdf.com/?x= ' => ' www.asdf.com/?x= ', |
---|
| 156 | ' www.asdf.com/?x ' => ' www.asdf.com/?x ', |
---|
| 157 | ' www.asdf.com/?â€ïž=ð¥ ' => ' www.asdf.com/?â€ïž=ð¥ ', |
---|
| 158 | ' www.asdf.com! ' => ' www.asdf.com! ', |
---|
| 159 | ' www.asdf.com. ' => ' www.asdf.com. ', |
---|
| 160 | ' `www.asdf.com` ' => ' `www.asdf.com` ', |
---|
| 161 | ' "www.asdf.com" ' => ' "www.asdf.com" ', |
---|
| 162 | ' <www.asdf.com> ' => ' <www.asdf.com> ', |
---|
| 163 | ' `http://www.asdf.com` ' => ' `http://www.asdf.com` ', |
---|
| 164 | ' "http://www.asdf.com" ' => ' "http://www.asdf.com" ', |
---|
| 165 | ' <http://www.asdf.com> ' => ' <<a href="http://www.asdf.com">www.asdf.com</a>> ', |
---|
| 166 | ' (http://www.asdf.com) ' => ' (<a href="http://www.asdf.com)">www.asdf.com)</a> ', |
---|
| 167 | ' (URL: http://www.asdf.com#1) ' => ' (URL: <a href="http://www.asdf.com#1)">www.asdf.com#1)</a> ', |
---|
| 168 | ' <a href="http://www.example.com/">Click Here</a> ' => ' <a href="http://www.example.com/">Click Here</a> ', |
---|
| 169 | ' <a href="http://www.example.com/">http://www.example.com/</a> ' => ' <a href="http://www.example.com/">http://www.example.com/</a> ', |
---|
| 170 | ' <a href=http://www.example.com/>http://www.example.com/</a> ' => ' <a href=http://www.example.com/>http://www.example.com/</a> ', |
---|
| 171 | ' <a href=\'http://www.example.com/\' >http://www.example.com/</a> ' => ' <a href=\'http://www.example.com/\' >http://www.example.com/</a> ', |
---|
| 172 | ' http://foo.com/blah_blah ' => ' <a href="http://foo.com/blah_blah">foo.com/blah_blah</a> ', |
---|
| 173 | ' http://foo.com/blah_blah/ ' => ' <a href="http://foo.com/blah_blah/">foo.com/blah_blah/</a> ', |
---|
| 174 | ' http://foo.com/blah_blah_(wikipedia) ' => ' <a href="http://foo.com/blah_blah_(wikipedia)">foo.com/blah_blah_(wikipedia)</a> ', |
---|
| 175 | ' http://foo.com/blah_blah_(wikipedia)_(again) ' => ' <a href="http://foo.com/blah_blah_(wikipedia)_(again)">foo.com/blah_blah_(wikipedia)_(again)</a> ', |
---|
| 176 | ' http://www.example.com/wpstyle/?p=364 ' => ' <a href="http://www.example.com/wpstyle/?p=364">www.example.com/wpstyle/?p=364</a> ', |
---|
| 177 | ' https://www.example.com/foo/?bar=baz&inga=42&quux ' => ' <a href="https://www.example.com/foo/?bar=baz&inga=42&quux">www.example.com/foo/?bar=baz&inga=42&quux</a> ', |
---|
| 178 | ' http://âªdf.ws/123 ' => ' <a href="http://âªdf.ws/123">âªdf.ws/123</a> ', |
---|
| 179 | ' http://userid:password@example.com:8080 ' => ' <a href="http://userid:password@example.com:8080">userid:password@example.com:8080</a> ', |
---|
| 180 | ' http://userid:password@example.com:8080/ ' => ' <a href="http://userid:password@example.com:8080/">userid:password@example.com:8080</a> ', |
---|
| 181 | ' http://userid@example.com ' => ' <a href="http://userid@example.com">userid@example.com</a> ', |
---|
| 182 | ' http://userid@example.com/ ' => ' <a href="http://userid@example.com/">userid@example.com</a> ', |
---|
| 183 | ' http://userid@example.com:8080 ' => ' <a href="http://userid@example.com:8080">userid@example.com:8080</a> ', |
---|
| 184 | ' http://userid@example.com:8080/ ' => ' <a href="http://userid@example.com:8080/">userid@example.com:8080</a> ', |
---|
| 185 | ' http://userid:password@example.com ' => ' <a href="http://userid:password@example.com">userid:password@example.com</a> ', |
---|
| 186 | ' http://userid:password@example.com/ ' => ' <a href="http://userid:password@example.com/">userid:password@example.com</a> ', |
---|
| 187 | ' http://142.42.1.1/ ' => ' <a href="http://142.42.1.1/">142.42.1.1</a> ', |
---|
| 188 | ' http://142.42.1.1:8080/ ' => ' <a href="http://142.42.1.1:8080/">142.42.1.1:8080</a> ', |
---|
| 189 | ' http://â¡.ws/äš¹ ' => ' <a href="http://â¡.ws/äš¹">â¡.ws/äš¹</a> ', |
---|
| 190 | ' http://â.ws ' => ' <a href="http://â.ws">â.ws</a> ', |
---|
| 191 | ' http://â.ws/ ' => ' <a href="http://â.ws/">â.ws</a> ', |
---|
| 192 | ' http://foo.com/blah_(wikipedia)#cite-1 ' => ' <a href="http://foo.com/blah_(wikipedia)#cite-1">foo.com/blah_(wikipedia)#cite-1</a> ', |
---|
| 193 | ' http://foo.com/blah_(wikipedia)_blah#cite-1 ' => ' <a href="http://foo.com/blah_(wikipedia)_blah#cite-1">foo.com/blah_(wikipedia)_blah#cite-1</a> ', |
---|
| 194 | ' http://foo.com/unicode_(âª)_in_parens ' => ' <a href="http://foo.com/unicode_(âª)_in_parens">foo.com/unicode_(âª)_in_parens</a> ', |
---|
| 195 | ' http://foo.com/(something)?after=parens ' => ' <a href="http://foo.com/(something)?after=parens">foo.com/(something)?after=parens</a> ', |
---|
| 196 | ' http://âº.damowmow.com/ ' => ' <a href="http://âº.damowmow.com/">âº.damowmow.com</a> ', |
---|
| 197 | ' http://code.google.com/events/#&product=browser ' => ' <a href="http://code.google.com/events/#&product=browser">code.google.com/events/#&product=browser</a> ', |
---|
| 198 | ' http://j.mp ' => ' <a href="http://j.mp">j.mp</a> ', |
---|
| 199 | ' ftp://foo.bar/baz ' => ' <a href="ftp://foo.bar/baz">ftp://foo.bar/baz</a> ', |
---|
| 200 | ' http://foo.bar/?q=Test%20URL-encoded%20stuff ' => ' <a href="http://foo.bar/?q=Test%20URL-encoded%20stuff">foo.bar/?q=Test%20URL-encoded%20stuff</a> ', |
---|
| 201 | ' http://Ù
ثاÙ.إختؚار ' => ' <a href="http://Ù
ثاÙ.إختؚار">Ù
ثاÙ.إختؚار</a> ', |
---|
| 202 | ' http://äŸå.æµè¯ ' => ' <a href="http://äŸå.æµè¯">äŸå.æµè¯</a> ', |
---|
| 203 | ' http://à€à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥à€à¥à€·à€Ÿ ' => ' <a href="http://à€à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥à€à¥à€·à€Ÿ">à€à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥à€à¥à€·à€Ÿ</a> ', |
---|
| 204 | ' http://-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com ' => ' <a href="http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com">-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com</a> ', |
---|
| 205 | ' http://1337.net ' => ' <a href="http://1337.net">1337.net</a> ', |
---|
| 206 | ' http://a.b-c.de ' => ' <a href="http://a.b-c.de">a.b-c.de</a> ', |
---|
| 207 | ' http://223.255.255.254 ' => ' <a href="http://223.255.255.254">223.255.255.254</a> ', |
---|
| 208 | ' http://foo.bar?q=Spaces should be encoded ' => ' <a href="http://foo.bar?q=Spaces">foo.bar?q=Spaces</a> should be encoded ', |
---|
| 209 | ' https://github.com/search?utf8=â&q=gif ' => ' <a href="https://github.com/search?utf8=â&q=gif">github.com/search?utf8=â&q=gif</a> ', |
---|
| 210 | ' https://github.com/search?q=gif&utf8=* ' => ' <a href="https://github.com/search?q=gif&utf8=*">github.com/search?q=gif&utf8=*</a> ', |
---|
| 211 | ' https://github.com/search?q=gif&utf8=â ' => ' <a href="https://github.com/search?q=gif&utf8=â">github.com/search?q=gif&utf8=â</a> ', |
---|
| 212 | |
---|
| 213 | // Unusual schemes. |
---|
| 214 | ' view-source:https://trac.strangecode.com/x/ticket/2#comment:4 ' => ' <a href="view-source:https://trac.strangecode.com/x/ticket/2#comment:4">view-source:https://trac.strangecode.com/x/ticket/2#comment:4</a> ', |
---|
| 215 | ' mailto:asdf@asdf.com ' => ' <a href="mailto:asdf@asdf.com">mailto:asdf@asdf.com</a> ', |
---|
| 216 | ' facetime://+19995551234 ' => ' <a href="facetime://+19995551234">facetime://+19995551234</a> ', |
---|
| 217 | ' tel:+15552001010 ' => ' <a href="tel:+15552001010">tel:+15552001010</a> ', |
---|
| 218 | ' magnet:?xt=urn:ed2k:354B15E68FB8F36D7CD88FF94116CDC1&xt=urn:tree:tiger:7N5OAMRNGMSSEUE3ORHOKWN4WWIQ5X4EBOOTLJY&xt=urn:btih:QHQXPYWMACKDWKP47RRVIV7VOURXFE5Q&xl=10826029&dn=mediawiki-1.15.1.tar.gz&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&as=http%3A%2F%2Fdownload.wikimedia.org%2Fmediawiki%2F1.15%2Fmediawiki-1.15.1.tar.gz&xs=http%3A%2F%2Fcache.example.org%2FXRX2PEFXOOEJFRVUCX6HMZMKS5TWG4K5&xs=dchub://example.org ' => ' <a href="magnet:?xt=urn:ed2k:354B15E68FB8F36D7CD88FF94116CDC1&xt=urn:tree:tiger:7N5OAMRNGMSSEUE3ORHOKWN4WWIQ5X4EBOOTLJY&xt=urn:btih:QHQXPYWMACKDWKP47RRVIV7VOURXFE5Q&xl=10826029&dn=mediawiki-1.15.1.tar.gz&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&as=http%3A%2F%2Fdownload.wikimedia.org%2Fmediawiki%2F1.15%2Fmediawiki-1.15.1.tar.gz&xs=http%3A%2F%2Fcache.example.org%2FXRX2PEFXOOEJFRVUCX6HMZMKS5TWG4K5&xs=dchub://example.org">magnet:?xt=urn:ed2k:354B15E68FB8F36D7CD88FF94116CDC1&xt=urn:tree:tiger:7N5OAMRNGMSSEUE3ORHOKWN4WWIQ5X4EBOOTLJY&xt=urn:btih:QHQXPYWMACKDWKP47RRVIV7VOURXFE5Q&xl=10826029&dn=mediawiki-1.15.1.tar.gz&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&as=http%3A%2F%2Fdownload.wikimedia.org%2Fmediawiki%2F1.15%2Fmediawiki-1.15.1.tar.gz&xs=http%3A%2F%2Fcache.example.org%2FXRX2PEFXOOEJFRVUCX6HMZMKS5TWG4K5&xs=dchub://example.org</a> ', |
---|
| 219 | ' chrome-extension://71f05c488a96b441ef679b09267ea46c/index.html ' => ' <a href="chrome-extension://71f05c488a96b441ef679b09267ea46c/index.html">chrome-extension://71f05c488a96b441ef679b09267ea46c/index.html</a> ', |
---|
| 220 | |
---|
| 221 | // These should fail. |
---|
| 222 | ' http://x and.co OK?' => ' http://x and.co OK?', |
---|
| 223 | ' www. ' => ' www. ', |
---|
| 224 | ' www.x ' => ' www.x ', |
---|
| 225 | ' http: ' => ' http: ', |
---|
| 226 | ' http:// ' => ' http:// ', |
---|
| 227 | ' http:x ' => ' http:x ', |
---|
| 228 | ' http://x ' => ' http://x ', |
---|
| 229 | ' http://x/ ' => ' http://x/ ', |
---|
| 230 | ' http:// www.x.com/ ' => ' http:// www.x.com/ ', |
---|
| 231 | ' http://?.com/ ' => ' http://?.com/ ', |
---|
| 232 | ' http://.?.com/ ' => ' http://.?.com/ ', |
---|
| 233 | |
---|
| 234 | // These are allowed to fuckup due to limitations in our ability to be omnipotent. |
---|
| 235 | ' <a href=http://www.example.com/ > http://www.example.com/</a> ' => ' <a href=http://www.example.com/ > <a href="http://www.example.com/">www.example.com</a></a> ', |
---|
| 236 | ' dummyhttp://www.asdf.com/ ' => ' <a href="dummyhttp://www.asdf.com/">dummyhttp://www.asdf.com/</a> ', |
---|
| 237 | |
---|
| 238 | '<a href="http://www.example.com">Lorem ipsum</a> <a href="sftp://user@host.tld/path">dolor sit amet</a> sftp://user@host.tld/path, [http://www.example.com/ consetetur] sadipscing elitr, (sed diam) www.example.com! Nonumy http://x.com! Invidunt mailto:asdf@asdf.com ut <a href="mailto:asdf@asdf.com">asdf@asdf.com</a> \'\'\'et dolore\'\'\' magna. <!-- comment --> Aliquyam:erat, sed://diam //voluptua//. At vero.eos.et {{{ for (var i = Things.length - 1; i >= 0; i--) { Things[i]; } }}} `http://x.com` justo duo doloreshttp://www.not.com!' => '<a href="http://www.example.com">Lorem ipsum</a> <a href="sftp://user@host.tld/path">dolor sit amet</a> <a href="sftp://user@host.tld/path,">sftp://user@host.tld/path,</a> [<a href="http://www.example.com/">www.example.com</a> consetetur] sadipscing elitr, (sed diam) www.example.com! Nonumy <a href="http://x.com!">x.com!</a> Invidunt <a href="mailto:asdf@asdf.com">mailto:asdf@asdf.com</a> ut <a href="mailto:asdf@asdf.com">asdf@asdf.com</a> \'\'\'et dolore\'\'\' magna. <!-- comment --> Aliquyam:erat, <a href="sed://diam">sed://diam</a> //voluptua//. At vero.eos.et {{{ for (var i = Things.length - 1; i >= 0; i--) { Things[i]; } }}} `http://x.com` justo duo <a href="doloreshttp://www.not.com!">doloreshttp://www.not.com!</a>', |
---|
| 239 | ]; |
---|
[541] | 240 | foreach ($urls as $input => $expected) { |
---|
| 241 | $result = hyperlinkTxt($input, false); |
---|
| 242 | $this->assertEquals($expected, $result, sprintf('Failed with input: %s', $input)); |
---|
| 243 | } |
---|
[545] | 244 | foreach ($urls_strict as $input => $expected) { |
---|
| 245 | // printf("'%s' => '%s',\n", $input, hyperlinkTxt($input, true)); |
---|
| 246 | $result = hyperlinkTxt($input, true); |
---|
| 247 | $this->assertEquals($expected, $result, sprintf('Failed with input: %s', $input)); |
---|
| 248 | } |
---|
[541] | 249 | } |
---|
| 250 | |
---|
[1] | 251 | } |
---|