3 if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
4 print "This script must be run from the command line\n";
8 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
9 define('STATUSNET', true);
11 require_once INSTALLDIR . '/lib/common.php';
13 class URLDetectionTest extends PHPUnit_Framework_TestCase
16 * @dataProvider provider
19 public function testProduction($content, $expected)
21 $rendered = common_render_text($content);
22 $this->assertEquals($expected, $rendered);
25 static public function provider()
28 array('not a link :: no way',
29 'not a link :: no way'),
30 array('link http://www.somesite.com/xyz/35637563@N00/52803365/ link',
31 'link <a href="http://www.somesite.com/xyz/35637563@N00/52803365/" rel="external">http://www.somesite.com/xyz/35637563@N00/52803365/</a> link'),
32 array('http://127.0.0.1',
33 '<a href="http://127.0.0.1/" rel="external">http://127.0.0.1</a>'),
35 '<a href="http://127.0.0.1/" rel="external">127.0.0.1</a>'),
37 '<a href="http://127.0.0.1:99/" rel="external">127.0.0.1:99</a>'),
38 array('127.0.0.1/Name:test.php',
39 '<a href="http://127.0.0.1/Name:test.php" rel="external">127.0.0.1/Name:test.php</a>'),
40 array('127.0.0.1/~test',
41 '<a href="http://127.0.0.1/~test" rel="external">127.0.0.1/~test</a>'),
42 array('127.0.0.1/+test',
43 '<a href="http://127.0.0.1/+test" rel="external">127.0.0.1/+test</a>'),
44 array('127.0.0.1/$test',
45 '<a href="http://127.0.0.1/$test" rel="external">127.0.0.1/$test</a>'),
46 array('127.0.0.1/\'test',
47 '<a href="http://127.0.0.1/\'test" rel="external">127.0.0.1/\'test</a>'),
48 array('127.0.0.1/"test',
49 '<a href="http://127.0.0.1/"test" rel="external">127.0.0.1/"test</a>'),
50 array('127.0.0.1/-test',
51 '<a href="http://127.0.0.1/-test" rel="external">127.0.0.1/-test</a>'),
52 array('127.0.0.1/_test',
53 '<a href="http://127.0.0.1/_test" rel="external">127.0.0.1/_test</a>'),
54 array('127.0.0.1/!test',
55 '<a href="http://127.0.0.1/!test" rel="external">127.0.0.1/!test</a>'),
56 array('127.0.0.1/*test',
57 '<a href="http://127.0.0.1/*test" rel="external">127.0.0.1/*test</a>'),
58 array('127.0.0.1/test%20stuff',
59 '<a href="http://127.0.0.1/test%20stuff" rel="external">127.0.0.1/test%20stuff</a>'),
60 array('http://[::1]:99/test.php',
61 '<a href="http://[::1]:99/test.php" rel="external">http://[::1]:99/test.php</a>'),
62 array('http://::1/test.php',
63 '<a href="http://::1/test.php" rel="external">http://::1/test.php</a>'),
65 '<a href="http://::1/" rel="external">http://::1</a>'),
66 array('2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php',
67 '<a href="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php" rel="external">2001:4978:1b5:0:21d:e0ff:fe66:59ab/test.php</a>'),
68 array('[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php',
69 '<a href="http://[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php" rel="external">[2001:4978:1b5:0:21d:e0ff:fe66:59ab]:99/test.php</a>'),
70 array('2001:4978:1b5:0:21d:e0ff:fe66:59ab',
71 '<a href="http://2001:4978:1b5:0:21d:e0ff:fe66:59ab/" rel="external">2001:4978:1b5:0:21d:e0ff:fe66:59ab</a>'),
72 array('http://127.0.0.1',
73 '<a href="http://127.0.0.1/" rel="external">http://127.0.0.1</a>'),
75 '<a href="http://example.com/" rel="external">example.com</a>'),
77 '<a href="http://example.com/" rel="external">example.com</a>'),
78 array('http://example.com',
79 '<a href="http://example.com/" rel="external">http://example.com</a>'),
80 array('http://example.com.',
81 '<a href="http://example.com/" rel="external">http://example.com</a>.'),
82 array('/var/lib/example.so',
83 '/var/lib/example.so'),
86 array('user@example.com',
87 '<a href="mailto:user@example.com" rel="external">user@example.com</a>'),
88 array('user_name+other@example.com',
89 '<a href="mailto:user_name+other@example.com" rel="external">user_name+other@example.com</a>'),
90 array('mailto:user@example.com',
91 '<a href="mailto:user@example.com" rel="external">mailto:user@example.com</a>'),
92 array('mailto:user@example.com?subject=test',
93 '<a href="mailto:user@example.com?subject=test" rel="external">mailto:user@example.com?subject=test</a>'),
95 '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('example'))) . '" rel="tag">example</a></span>'),
97 '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('example.com'))) . '" rel="tag">example.com</a></span>'),
99 '#<span class="tag"><a href="' . common_local_url('tag', array('tag' => common_canonical_tag('.net'))) . '" rel="tag">.net</a></span>'),
100 array('http://example',
101 '<a href="http://example/" rel="external">http://example</a>'),
102 array('http://3xampl3',
103 '<a href="http://3xampl3/" rel="external">http://3xampl3</a>'),
104 array('http://example/',
105 '<a href="http://example/" rel="external">http://example/</a>'),
106 array('http://example/path',
107 '<a href="http://example/path" rel="external">http://example/path</a>'),
108 array('http://example.com',
109 '<a href="http://example.com/" rel="external">http://example.com</a>'),
110 array('https://example.com',
111 '<a href="https://example.com/" rel="external">https://example.com</a>'),
112 array('ftp://example.com',
113 '<a href="ftp://example.com/" rel="external">ftp://example.com</a>'),
114 array('ftps://example.com',
115 '<a href="ftps://example.com/" rel="external">ftps://example.com</a>'),
116 array('http://user@example.com',
117 '<a href="http://user@example.com/" rel="external">http://user@example.com</a>'),
118 array('http://user:pass@example.com',
119 '<a href="http://user:pass@example.com/" rel="external">http://user:pass@example.com</a>'),
120 array('http://example.com:8080',
121 '<a href="http://example.com:8080/" rel="external">http://example.com:8080</a>'),
122 array('http://example.com:8080/test.php',
123 '<a href="http://example.com:8080/test.php" rel="external">http://example.com:8080/test.php</a>'),
124 array('example.com:8080/test.php',
125 '<a href="http://example.com:8080/test.php" rel="external">example.com:8080/test.php</a>'),
126 array('http://www.example.com',
127 '<a href="http://www.example.com/" rel="external">http://www.example.com</a>'),
128 array('http://example.com/',
129 '<a href="http://example.com/" rel="external">http://example.com/</a>'),
130 array('http://example.com/path',
131 '<a href="http://example.com/path" rel="external">http://example.com/path</a>'),
132 array('http://example.com/path.html',
133 '<a href="http://example.com/path.html" rel="external">http://example.com/path.html</a>'),
134 array('http://example.com/path.html#fragment',
135 '<a href="http://example.com/path.html#fragment" rel="external">http://example.com/path.html#fragment</a>'),
136 array('http://example.com/path.php?foo=bar&bar=foo',
137 '<a href="http://example.com/path.php?foo=bar&bar=foo" rel="external">http://example.com/path.php?foo=bar&bar=foo</a>'),
138 array('http://example.com.',
139 '<a href="http://example.com/" rel="external">http://example.com</a>.'),
140 array('http://müllärör.de',
141 '<a href="http://müllärör.de/" rel="external">http://müllärör.de</a>'),
142 array('http://ﺱﺲﺷ.com',
143 '<a href="http://ﺱﺲﺷ.com/" rel="external">http://ﺱﺲﺷ.com</a>'),
144 array('http://сделаткартинки.com',
145 '<a href="http://сделаткартинки.com/" rel="external">http://сделаткартинки.com</a>'),
146 array('http://tūdaliņ.lv',
147 '<a href="http://tūdaliņ.lv/" rel="external">http://tūdaliņ.lv</a>'),
148 array('http://brændendekærlighed.com',
149 '<a href="http://brændendekærlighed.com/" rel="external">http://brændendekærlighed.com</a>'),
150 array('http://あーるいん.com',
151 '<a href="http://あーるいん.com/" rel="external">http://あーるいん.com</a>'),
152 array('http://예비교사.com',
153 '<a href="http://예비교사.com/" rel="external">http://예비교사.com</a>'),
154 array('http://example.com.',
155 '<a href="http://example.com/" rel="external">http://example.com</a>.'),
156 array('http://example.com?',
157 '<a href="http://example.com/" rel="external">http://example.com</a>?'),
158 array('http://example.com!',
159 '<a href="http://example.com/" rel="external">http://example.com</a>!'),
160 array('http://example.com,',
161 '<a href="http://example.com/" rel="external">http://example.com</a>,'),
162 array('http://example.com;',
163 '<a href="http://example.com/" rel="external">http://example.com</a>;'),
164 array('http://example.com:',
165 '<a href="http://example.com/" rel="external">http://example.com</a>:'),
166 array('\'http://example.com\'',
167 '\'<a href="http://example.com/" rel="external">http://example.com</a>\''),
168 array('"http://example.com"',
169 '"<a href="http://example.com/" rel="external">http://example.com</a>"'),
170 array('http://example.com',
171 '<a href="http://example.com/" rel="external">http://example.com</a>'),
172 array('(http://example.com)',
173 '(<a href="http://example.com/" rel="external">http://example.com</a>)'),
174 array('[http://example.com]',
175 '[<a href="http://example.com/" rel="external">http://example.com</a>]'),
176 array('<http://example.com>',
177 '<<a href="http://example.com/" rel="external">http://example.com</a>>'),
178 array('http://example.com/path/(foo)/bar',
179 '<a href="http://example.com/path/(foo)/bar" rel="external">http://example.com/path/(foo)/bar</a>'),
180 array('http://example.com/path/[foo]/bar',
181 '<a href="http://example.com/path/[foo]/bar" rel="external">http://example.com/path/[foo]/bar</a>'),
182 array('http://example.com/path/foo/(bar)',
183 '<a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>'),
184 //Not a valid url - urls cannot contain unencoded square brackets
185 array('http://example.com/path/foo/[bar]',
186 '<a href="http://example.com/path/foo/[bar]" rel="external">http://example.com/path/foo/[bar]</a>'),
187 array('Hey, check out my cool site http://example.com okay?',
188 'Hey, check out my cool site <a href="http://example.com/" rel="external">http://example.com</a> okay?'),
189 array('What about parens (e.g. http://example.com/path/foo/(bar))?',
190 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>)?'),
191 array('What about parens (e.g. http://example.com/path/foo/(bar)?',
192 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>?'),
193 array('What about parens (e.g. http://example.com/path/foo/(bar).)?',
194 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>.)?'),
195 //Not a valid url - urls cannot contain unencoded commas
196 array('What about parens (e.g. http://example.com/path/(foo,bar)?',
197 'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" rel="external">http://example.com/path/(foo,bar)</a>?'),
198 array('Unbalanced too (e.g. http://example.com/path/((((foo)/bar)?',
199 'Unbalanced too (e.g. <a href="http://example.com/path/((((foo)/bar)" rel="external">http://example.com/path/((((foo)/bar)</a>?'),
200 array('Unbalanced too (e.g. http://example.com/path/(foo))))/bar)?',
201 'Unbalanced too (e.g. <a href="http://example.com/path/(foo))))/bar" rel="external">http://example.com/path/(foo))))/bar</a>)?'),
202 array('Unbalanced too (e.g. http://example.com/path/foo/((((bar)?',
203 'Unbalanced too (e.g. <a href="http://example.com/path/foo/((((bar)" rel="external">http://example.com/path/foo/((((bar)</a>?'),
204 array('Unbalanced too (e.g. http://example.com/path/foo/(bar))))?',
205 'Unbalanced too (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">http://example.com/path/foo/(bar)</a>)))?'),
207 '<a href="http://example.com/" rel="external">example.com</a>'),
209 '<a href="http://example.org/" rel="external">example.org</a>'),
210 array('example.co.uk',
211 '<a href="http://example.co.uk/" rel="external">example.co.uk</a>'),
212 array('www.example.co.uk',
213 '<a href="http://www.example.co.uk/" rel="external">www.example.co.uk</a>'),
214 array('farm1.images.example.co.uk',
215 '<a href="http://farm1.images.example.co.uk/" rel="external">farm1.images.example.co.uk</a>'),
216 array('example.museum',
217 '<a href="http://example.museum/" rel="external">example.museum</a>'),
218 array('example.travel',
219 '<a href="http://example.travel/" rel="external">example.travel</a>'),
220 array('example.com.',
221 '<a href="http://example.com/" rel="external">example.com</a>.'),
222 array('example.com?',
223 '<a href="http://example.com/" rel="external">example.com</a>?'),
224 array('example.com!',
225 '<a href="http://example.com/" rel="external">example.com</a>!'),
226 array('example.com,',
227 '<a href="http://example.com/" rel="external">example.com</a>,'),
228 array('example.com;',
229 '<a href="http://example.com/" rel="external">example.com</a>;'),
230 array('example.com:',
231 '<a href="http://example.com/" rel="external">example.com</a>:'),
232 array('\'example.com\'',
233 '\'<a href="http://example.com/" rel="external">example.com</a>\''),
234 array('"example.com"',
235 '"<a href="http://example.com/" rel="external">example.com</a>"'),
237 '<a href="http://example.com/" rel="external">example.com</a>'),
238 array('(example.com)',
239 '(<a href="http://example.com/" rel="external">example.com</a>)'),
240 array('[example.com]',
241 '[<a href="http://example.com/" rel="external">example.com</a>]'),
242 array('<example.com>',
243 '<<a href="http://example.com/" rel="external">example.com</a>>'),
244 array('Hey, check out my cool site example.com okay?',
245 'Hey, check out my cool site <a href="http://example.com/" rel="external">example.com</a> okay?'),
246 array('Hey, check out my cool site example.com.I made it.',
247 'Hey, check out my cool site <a href="http://example.com/" rel="external">example.com</a>.I made it.'),
248 array('Hey, check out my cool site example.com.Funny thing...',
249 'Hey, check out my cool site <a href="http://example.com/" rel="external">example.com</a>.Funny thing...'),
250 array('Hey, check out my cool site example.com.You will love it.',
251 'Hey, check out my cool site <a href="http://example.com/" rel="external">example.com</a>.You will love it.'),
252 array('What about parens (e.g. example.com/path/foo/(bar))?',
253 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">example.com/path/foo/(bar)</a>)?'),
254 array('What about parens (e.g. example.com/path/foo/(bar)?',
255 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">example.com/path/foo/(bar)</a>?'),
256 array('What about parens (e.g. example.com/path/foo/(bar).)?',
257 'What about parens (e.g. <a href="http://example.com/path/foo/(bar)" rel="external">example.com/path/foo/(bar)</a>.)?'),
258 array('What about parens (e.g. example.com/path/(foo,bar)?',
259 'What about parens (e.g. <a href="http://example.com/path/(foo,bar)" rel="external">example.com/path/(foo,bar)</a>?'),