- Timestamp:
- Aug 19, 2015 4:18:55 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/docs/examples/_config.inc.php
r480 r545 84 84 'error_reporting' => E_ALL & ~E_DEPRECATED & ~E_STRICT, 85 85 86 'log_directory' => COMMON_BASE . '/log',86 'log_directory' => '/tmp', 87 87 'log_filename' => 'site_log', 88 88 'log_file_priority' => LOG_DEBUG, -
trunk/lib/Utilities.inc.php
r544 r545 225 225 function hyperlinkTxt($text, $strict=false, $length=null, $delim='âŠ') 226 226 { 227 // A list of schemes we allow at the beginning of a URL. 228 $schemes = 'mailto:|tel:|skype:|callto:|facetime:|bitcoin:|geo:|magnet:\?|sip:|sms:|xmpp:|view-source:(?:https?://)?|[\w-]{2,}://'; 229 227 230 // Capture the full URL into the first match and only the first X characters into the second match. 228 231 // This will match URLs not preceeded by " ' or = (URLs inside an attribute) or ` (Markdown quoted) or double-scheme (http://http://www.asdf.com) … … 233 236 ( # Begin match 1 234 237 ( # Begin match 2 235 (?: [\w-]{2,}://%s) # URL starts with SCHEME:// or www. (if strict = false)238 (?:%s) # URL starts with known scheme or www. if strict = false 236 239 [^\s/$.?#]+ # Any domain-valid characters 237 \. # At least one point238 240 [^\s"`<>]{1,%s} # Match 2 is limited to a maximum of LENGTH valid URL characters 239 241 ) 240 242 [^\s"`<>]* # Match 1 continues with any further valid URL characters 241 [^\P{Any}\sâŠ<>«»"ââ%s]# Final character not a space or common end-of-sentence punctuation (.,:;?!, etc). Using double negation set, see http://stackoverflow.com/a/4786560/277303243 ([^\P{Any}\sâŠ<>«»"ââ%s]) # Final character not a space or common end-of-sentence punctuation (.,:;?!, etc). Using double negation set, see http://stackoverflow.com/a/4786560/277303 242 244 ) 243 245 @Suxi 244 246 '; 245 247 $regex = sprintf($regex, 246 ($strict ? '' : '|www\.'), // Strict=false allows URLs beginning with www.247 $length,248 ($strict ? '' : '?!.,:;)\'-') // Strict=false excludes these characters as a possible last character of URL.248 ($strict ? $schemes : $schemes . '|www\.'), // Strict=false adds "www." to the list of allowed start-of-URL. 249 ($length ? $length : ''), 250 ($strict ? '' : '?!.,:;)\'-') // Strict=false excludes some "URL-valid" characters from the last character of URL. (Hyphen must remain last character in this class.) 249 251 ); 250 252 … … 253 255 return preg_replace_callback($regex, function ($m) use ($length, $delim) { 254 256 $url = $m[1]; 255 $truncated_url = $m[2] ;257 $truncated_url = $m[2] . $m[3]; 256 258 $absolute_url = preg_replace('!^www\.!', 'http://www.', $url); 257 259 if (is_null($length) || $url == $truncated_url) { 258 260 // If not truncating, or URL was not truncated. 259 $display_url = preg_replace('!^[\w-]{2,}://!', '', $url); 261 // Remove http schemas, and any single trailing / to make the display URL. 262 $display_url = preg_replace(['!^https?://!', '!^([^/]+)/$!'], ['', '$1'], $url); 260 263 return sprintf('<a href="%s">%s</a>', oTxt($absolute_url), $display_url); 261 264 } else { 262 265 // Truncated URL. 263 $display_url = preg_replace('!^[\w-]{2,}://!', '', trim($truncated_url)); 266 // Remove http schemas, and any single trailing / to make the display URL. 267 $display_url = preg_replace(['!^https?://!', '!^([^/]+)/$!'], ['', '$1'], trim($truncated_url)); 264 268 return sprintf('<a href="%s">%s%s</a>', oTxt($absolute_url), $display_url, $delim); 265 269 } -
trunk/tests/UtilitiesTest.php
r541 r545 50 50 { 51 51 $urls = [ 52 ' http://www.asdf.com/ ' => ' <a href="http://www.asdf.com/">www.asdf.com/</a> ', 53 ' www.asdf.com/ ' => ' <a href="http://www.asdf.com/">www.asdf.com/</a> ', 54 ' www.asdf.com/? ' => ' <a href="http://www.asdf.com/">www.asdf.com/</a>? ', 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>? ', 55 58 ' www.asdf.com/?x=y+z ' => ' <a href="http://www.asdf.com/?x=y+z">www.asdf.com/?x=y+z</a> ', 56 59 ' www.asdf.com/?x=y+ ' => ' <a href="http://www.asdf.com/?x=y+">www.asdf.com/?x=y+</a> ', … … 79 82 ' http://âªdf.ws/123 ' => ' <a href="http://âªdf.ws/123">âªdf.ws/123</a> ', 80 83 ' http://userid:password@example.com:8080 ' => ' <a href="http://userid:password@example.com:8080">userid:password@example.com:8080</a> ', 81 ' http://userid:password@example.com:8080/ ' => ' <a href="http://userid:password@example.com:8080/">userid:password@example.com:8080 /</a> ',84 ' http://userid:password@example.com:8080/ ' => ' <a href="http://userid:password@example.com:8080/">userid:password@example.com:8080</a> ', 82 85 ' http://userid@example.com ' => ' <a href="http://userid@example.com">userid@example.com</a> ', 83 ' http://userid@example.com/ ' => ' <a href="http://userid@example.com/">userid@example.com /</a> ',86 ' http://userid@example.com/ ' => ' <a href="http://userid@example.com/">userid@example.com</a> ', 84 87 ' http://userid@example.com:8080 ' => ' <a href="http://userid@example.com:8080">userid@example.com:8080</a> ', 85 ' http://userid@example.com:8080/ ' => ' <a href="http://userid@example.com:8080/">userid@example.com:8080 /</a> ',88 ' http://userid@example.com:8080/ ' => ' <a href="http://userid@example.com:8080/">userid@example.com:8080</a> ', 86 89 ' http://userid:password@example.com ' => ' <a href="http://userid:password@example.com">userid:password@example.com</a> ', 87 ' http://userid:password@example.com/ ' => ' <a href="http://userid:password@example.com/">userid:password@example.com /</a> ',88 ' http://142.42.1.1/ ' => ' <a href="http://142.42.1.1/">142.42.1.1 /</a> ',89 ' http://142.42.1.1:8080/ ' => ' <a href="http://142.42.1.1:8080/">142.42.1.1:8080 /</a> ',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> ', 90 93 ' http://â¡.ws/äš¹ ' => ' <a href="http://â¡.ws/äš¹">â¡.ws/äš¹</a> ', 91 94 ' http://â.ws ' => ' <a href="http://â.ws">â.ws</a> ', 92 ' http://â.ws/ ' => ' <a href="http://â.ws/">â.ws /</a> ',95 ' http://â.ws/ ' => ' <a href="http://â.ws/">â.ws</a> ', 93 96 ' http://foo.com/blah_(wikipedia)#cite-1 ' => ' <a href="http://foo.com/blah_(wikipedia)#cite-1">foo.com/blah_(wikipedia)#cite-1</a> ', 94 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> ', 95 98 ' http://foo.com/unicode_(âª)_in_parens ' => ' <a href="http://foo.com/unicode_(âª)_in_parens">foo.com/unicode_(âª)_in_parens</a> ', 96 99 ' http://foo.com/(something)?after=parens ' => ' <a href="http://foo.com/(something)?after=parens">foo.com/(something)?after=parens</a> ', 97 ' http://âº.damowmow.com/ ' => ' <a href="http://âº.damowmow.com/">âº.damowmow.com /</a> ',100 ' http://âº.damowmow.com/ ' => ' <a href="http://âº.damowmow.com/">âº.damowmow.com</a> ', 98 101 ' http://code.google.com/events/#&product=browser ' => ' <a href="http://code.google.com/events/#&product=browser">code.google.com/events/#&product=browser</a> ', 99 102 ' http://j.mp ' => ' <a href="http://j.mp">j.mp</a> ', 100 ' ftp://foo.bar/baz ' => ' <a href="ftp://foo.bar/baz">f oo.bar/baz</a> ',103 ' ftp://foo.bar/baz ' => ' <a href="ftp://foo.bar/baz">ftp://foo.bar/baz</a> ', 101 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> ', 102 105 ' http://Ù … … 116 119 ' https://github.com/search?q=gif&utf8=â ' => ' <a href="https://github.com/search?q=gif&utf8=â">github.com/search?q=gif&utf8=â</a> ', 117 120 121 // These should fail. 122 ' http://x and.co OK?' => ' http://x and.co OK?', 123 ' www. ' => ' www. ', 124 ' www.x ' => ' www.x ', 125 ' http: ' => ' http: ', 126 ' http:// ' => ' http:// ', 127 ' http:x ' => ' http:x ', 128 ' http://x ' => ' http://x ', 129 ' http://x/ ' => ' http://x/ ', 130 ' http:// ?.x.com/ ' => ' http:// ?.x.com/ ', 131 ' http://?.com/ ' => ' http://?.com/ ', 132 ' http://.?.com/ ' => ' http://.?.com/ ', 133 118 134 // These are allowed to fuckup due to limitations in our ability to be omnipotent. 119 ' <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> ', 135 ' http:// www.x.com/ ' => ' http:// <a href="http://www.x.com/">www.x.com</a> ', 136 ' <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> ', 137 138 '<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>!', 139 ]; 140 141 $urls_strict = [ 142 ' http://www.asdf.com/ ' => ' <a href="http://www.asdf.com/">www.asdf.com</a> ', 143 ' ws://www.asdf.com/ ' => ' <a href="ws://www.asdf.com/">ws://www.asdf.com/</a> ', 144 ' sftp://user@host.tld:22/path/x ' => ' <a href="sftp://user@host.tld:22/path/x">sftp://user@host.tld:22/path/x</a> ', 145 ' sip:beer ' => ' <a href="sip:beer">sip:beer</a> ', 146 ' http://asdf/ ' => ' <a href="http://asdf/">asdf</a> ', 147 ' http://www.asdf.com/? ' => ' <a href="http://www.asdf.com/?">www.asdf.com/?</a> ', 148 ' http://www.asdf.com/?x=y+z ' => ' <a href="http://www.asdf.com/?x=y+z">www.asdf.com/?x=y+z</a> ', 149 ' http://www.asdf.com/?x=y+ ' => ' <a href="http://www.asdf.com/?x=y+">www.asdf.com/?x=y+</a> ', 150 ' http://www.asdf.com/?x= ' => ' <a href="http://www.asdf.com/?x=">www.asdf.com/?x=</a> ', 151 ' http://www.asdf.com/?x ' => ' <a href="http://www.asdf.com/?x">www.asdf.com/?x</a> ', 152 ' https://www.asdf.com/?â€ïž=ð¥ ' => ' <a href="https://www.asdf.com/?â€ïž=ð¥">www.asdf.com/?â€ïž=ð¥</a> ', 153 ' www.asdf.com? ' => ' www.asdf.com? ', 154 ' www.asdf.com/ ' => ' www.asdf.com/ ', 155 ' www.asdf.com/? ' => ' www.asdf.com/? ', 156 ' www.asdf.com/?x=y+z ' => ' www.asdf.com/?x=y+z ', 157 ' www.asdf.com/?x=y+ ' => ' www.asdf.com/?x=y+ ', 158 ' www.asdf.com/?x= ' => ' www.asdf.com/?x= ', 159 ' www.asdf.com/?x ' => ' www.asdf.com/?x ', 160 ' www.asdf.com/?â€ïž=ð¥ ' => ' www.asdf.com/?â€ïž=ð¥ ', 161 ' www.asdf.com! ' => ' www.asdf.com! ', 162 ' www.asdf.com. ' => ' www.asdf.com. ', 163 ' `www.asdf.com` ' => ' `www.asdf.com` ', 164 ' "www.asdf.com" ' => ' "www.asdf.com" ', 165 ' <www.asdf.com> ' => ' <www.asdf.com> ', 166 ' `http://www.asdf.com` ' => ' `http://www.asdf.com` ', 167 ' "http://www.asdf.com" ' => ' "http://www.asdf.com" ', 168 ' <http://www.asdf.com> ' => ' <<a href="http://www.asdf.com">www.asdf.com</a>> ', 169 ' (http://www.asdf.com) ' => ' (<a href="http://www.asdf.com)">www.asdf.com)</a> ', 170 ' (URL: http://www.asdf.com#1) ' => ' (URL: <a href="http://www.asdf.com#1)">www.asdf.com#1)</a> ', 171 ' <a href="http://www.example.com/">Click Here</a> ' => ' <a href="http://www.example.com/">Click Here</a> ', 172 ' <a href="http://www.example.com/">http://www.example.com/</a> ' => ' <a href="http://www.example.com/">http://www.example.com/</a> ', 173 ' <a href=http://www.example.com/>http://www.example.com/</a> ' => ' <a href=http://www.example.com/>http://www.example.com/</a> ', 174 ' <a href=\'http://www.example.com/\' >http://www.example.com/</a> ' => ' <a href=\'http://www.example.com/\' >http://www.example.com/</a> ', 175 ' http://foo.com/blah_blah ' => ' <a href="http://foo.com/blah_blah">foo.com/blah_blah</a> ', 176 ' http://foo.com/blah_blah/ ' => ' <a href="http://foo.com/blah_blah/">foo.com/blah_blah/</a> ', 177 ' http://foo.com/blah_blah_(wikipedia) ' => ' <a href="http://foo.com/blah_blah_(wikipedia)">foo.com/blah_blah_(wikipedia)</a> ', 178 ' http://foo.com/blah_blah_(wikipedia)_(again) ' => ' <a href="http://foo.com/blah_blah_(wikipedia)_(again)">foo.com/blah_blah_(wikipedia)_(again)</a> ', 179 ' http://www.example.com/wpstyle/?p=364 ' => ' <a href="http://www.example.com/wpstyle/?p=364">www.example.com/wpstyle/?p=364</a> ', 180 ' 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> ', 181 ' http://âªdf.ws/123 ' => ' <a href="http://âªdf.ws/123">âªdf.ws/123</a> ', 182 ' http://userid:password@example.com:8080 ' => ' <a href="http://userid:password@example.com:8080">userid:password@example.com:8080</a> ', 183 ' http://userid:password@example.com:8080/ ' => ' <a href="http://userid:password@example.com:8080/">userid:password@example.com:8080</a> ', 184 ' http://userid@example.com ' => ' <a href="http://userid@example.com">userid@example.com</a> ', 185 ' http://userid@example.com/ ' => ' <a href="http://userid@example.com/">userid@example.com</a> ', 186 ' http://userid@example.com:8080 ' => ' <a href="http://userid@example.com:8080">userid@example.com:8080</a> ', 187 ' http://userid@example.com:8080/ ' => ' <a href="http://userid@example.com:8080/">userid@example.com:8080</a> ', 188 ' http://userid:password@example.com ' => ' <a href="http://userid:password@example.com">userid:password@example.com</a> ', 189 ' http://userid:password@example.com/ ' => ' <a href="http://userid:password@example.com/">userid:password@example.com</a> ', 190 ' http://142.42.1.1/ ' => ' <a href="http://142.42.1.1/">142.42.1.1</a> ', 191 ' http://142.42.1.1:8080/ ' => ' <a href="http://142.42.1.1:8080/">142.42.1.1:8080</a> ', 192 ' http://â¡.ws/äš¹ ' => ' <a href="http://â¡.ws/äš¹">â¡.ws/äš¹</a> ', 193 ' http://â.ws ' => ' <a href="http://â.ws">â.ws</a> ', 194 ' http://â.ws/ ' => ' <a href="http://â.ws/">â.ws</a> ', 195 ' http://foo.com/blah_(wikipedia)#cite-1 ' => ' <a href="http://foo.com/blah_(wikipedia)#cite-1">foo.com/blah_(wikipedia)#cite-1</a> ', 196 ' 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> ', 197 ' http://foo.com/unicode_(âª)_in_parens ' => ' <a href="http://foo.com/unicode_(âª)_in_parens">foo.com/unicode_(âª)_in_parens</a> ', 198 ' http://foo.com/(something)?after=parens ' => ' <a href="http://foo.com/(something)?after=parens">foo.com/(something)?after=parens</a> ', 199 ' http://âº.damowmow.com/ ' => ' <a href="http://âº.damowmow.com/">âº.damowmow.com</a> ', 200 ' http://code.google.com/events/#&product=browser ' => ' <a href="http://code.google.com/events/#&product=browser">code.google.com/events/#&product=browser</a> ', 201 ' http://j.mp ' => ' <a href="http://j.mp">j.mp</a> ', 202 ' ftp://foo.bar/baz ' => ' <a href="ftp://foo.bar/baz">ftp://foo.bar/baz</a> ', 203 ' 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> ', 204 ' http://Ù 205 ثاÙ.إختؚار ' => ' <a href="http://Ù 206 ثاÙ.إختؚار">Ù 207 ثاÙ.إختؚار</a> ', 208 ' http://äŸå.æµè¯ ' => ' <a href="http://äŸå.æµè¯">äŸå.æµè¯</a> ', 209 ' http://à€à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥à€à¥à€·à€Ÿ ' => ' <a href="http://à€à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥à€à¥à€·à€Ÿ">à€à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥à€à¥à€·à€Ÿ</a> ', 210 ' http://-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com ' => ' <a href="http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com">-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com</a> ', 211 ' http://1337.net ' => ' <a href="http://1337.net">1337.net</a> ', 212 ' http://a.b-c.de ' => ' <a href="http://a.b-c.de">a.b-c.de</a> ', 213 ' http://223.255.255.254 ' => ' <a href="http://223.255.255.254">223.255.255.254</a> ', 214 ' http://foo.bar?q=Spaces should be encoded ' => ' <a href="http://foo.bar?q=Spaces">foo.bar?q=Spaces</a> should be encoded ', 215 ' https://github.com/search?utf8=â&q=gif ' => ' <a href="https://github.com/search?utf8=â&q=gif">github.com/search?utf8=â&q=gif</a> ', 216 ' https://github.com/search?q=gif&utf8=* ' => ' <a href="https://github.com/search?q=gif&utf8=*">github.com/search?q=gif&utf8=*</a> ', 217 ' https://github.com/search?q=gif&utf8=â ' => ' <a href="https://github.com/search?q=gif&utf8=â">github.com/search?q=gif&utf8=â</a> ', 218 219 // Unusual schemes. 220 ' 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> ', 221 ' mailto:asdf@asdf.com ' => ' <a href="mailto:asdf@asdf.com">mailto:asdf@asdf.com</a> ', 222 ' facetime://+19995551234 ' => ' <a href="facetime://+19995551234">facetime://+19995551234</a> ', 223 ' tel:+15552001010 ' => ' <a href="tel:+15552001010">tel:+15552001010</a> ', 224 ' 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> ', 225 ' chrome-extension://71f05c488a96b441ef679b09267ea46c/index.html ' => ' <a href="chrome-extension://71f05c488a96b441ef679b09267ea46c/index.html">chrome-extension://71f05c488a96b441ef679b09267ea46c/index.html</a> ', 226 227 // These should fail. 228 ' http://x and.co OK?' => ' http://x and.co OK?', 229 ' www. ' => ' www. ', 230 ' www.x ' => ' www.x ', 231 ' http: ' => ' http: ', 232 ' http:// ' => ' http:// ', 233 ' http:x ' => ' http:x ', 234 ' http://x ' => ' http://x ', 235 ' http://x/ ' => ' http://x/ ', 236 ' http:// www.x.com/ ' => ' http:// www.x.com/ ', 237 ' http://?.com/ ' => ' http://?.com/ ', 238 ' http://.?.com/ ' => ' http://.?.com/ ', 239 240 // These are allowed to fuckup due to limitations in our ability to be omnipotent. 241 ' <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> ', 242 ' dummyhttp://www.asdf.com/ ' => ' <a href="dummyhttp://www.asdf.com/">dummyhttp://www.asdf.com/</a> ', 243 244 '<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>', 120 245 ]; 121 246 foreach ($urls as $input => $expected) { … … 123 248 $this->assertEquals($expected, $result, sprintf('Failed with input: %s', $input)); 124 249 } 250 foreach ($urls_strict as $input => $expected) { 251 // printf("'%s' => '%s',\n", $input, hyperlinkTxt($input, true)); 252 $result = hyperlinkTxt($input, true); 253 $this->assertEquals($expected, $result, sprintf('Failed with input: %s', $input)); 254 } 125 255 } 126 256
Note: See TracChangeset
for help on using the changeset viewer.