Changeset 541


Ignore:
Timestamp:
Aug 12, 2015 12:22:54 AM (9 years ago)
Author:
anonymous
Message:

v2.2.0-3: Fixed auth password hashing verification issues. Updated hyperlinkTxt() with option. Updated tests.

Location:
trunk
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/version.txt

    r524 r541  
    1 2.2.0dev
     12.2.0-3
  • trunk/lib/Auth_SQL.inc.php

    r535 r541  
    627627            && !empty($_SESSION['_auth_sql'][$this->_ns]['username'])
    628628            && isset($_SESSION['_auth_sql'][$this->_ns]['login_datetime'])
    629             && strtotime($_SESSION['_auth_sql'][$this->_ns]['login_datetime']) > time() - $this->_params['login_timeout']
     629            && strtotime($_SESSION['_auth_sql'][$this->_ns]['login_datetime']) > (time() - $this->_params['login_timeout'])
    630630            && isset($_SESSION['_auth_sql'][$this->_ns]['last_access_datetime'])
    631             && strtotime($_SESSION['_auth_sql'][$this->_ns]['last_access_datetime']) > time() - $this->_params['idle_timeout']
     631            && strtotime($_SESSION['_auth_sql'][$this->_ns]['last_access_datetime']) > (time() - $this->_params['idle_timeout'])
    632632            && $remote_ip_is_matched
    633633        ) {
     
    650650        } else if (isset($_SESSION['_auth_sql'][$this->_ns]['authenticated']) && true === $_SESSION['_auth_sql'][$this->_ns]['authenticated']) {
    651651            // User is authenticated, but login has expired.
    652             if (strtotime($_SESSION['_auth_sql'][$this->_ns]['last_access_datetime']) > time() - 43200) {
     652            if (strtotime($_SESSION['_auth_sql'][$this->_ns]['last_access_datetime']) > (time() - 43200)) {
    653653                // Only raise message if last session is less than 12 hours old.
    654654                $app->raiseMsg(_("Your session has expired. You need to log-in again."), MSG_NOTICE, __FILE__, __LINE__);
     
    657657            // Log the reason for login expiration.
    658658            $expire_reasons = array();
    659             if (empty($_SESSION['_auth_sql'][$this->_ns]['username'])) {
     659            if (!isset($_SESSION['_auth_sql'][$this->_ns]['username']) || empty($_SESSION['_auth_sql'][$this->_ns]['username'])) {
    660660                $expire_reasons[] = 'username not found';
    661661            }
    662             if (strtotime($_SESSION['_auth_sql'][$this->_ns]['login_datetime']) <= time() - $this->_params['login_timeout']) {
     662            if (!isset($_SESSION['_auth_sql'][$this->_ns]['login_datetime']) || strtotime($_SESSION['_auth_sql'][$this->_ns]['login_datetime']) <= (time() - $this->_params['login_timeout'])) {
    663663                $expire_reasons[] = sprintf('login_timeout expired (%s older than %s seconds ago)', $_SESSION['_auth_sql'][$this->_ns]['login_datetime'], $this->_params['login_timeout']);
    664664            }
    665             if (strtotime($_SESSION['_auth_sql'][$this->_ns]['last_access_datetime']) <= time() - $this->_params['idle_timeout']) {
     665            if (!isset($_SESSION['_auth_sql'][$this->_ns]['last_access_datetime']) || strtotime($_SESSION['_auth_sql'][$this->_ns]['last_access_datetime']) <= (time() - $this->_params['idle_timeout'])) {
    666666                $expire_reasons[] = sprintf('idle_timeout expired (%s older than %s seconds ago)', $_SESSION['_auth_sql'][$this->_ns]['last_access_datetime'], $this->_params['idle_timeout']);
    667667            }
    668             if ($_SESSION['_auth_sql'][$this->_ns]['remote_ip'] != getRemoteAddr()) {
     668            if (!isset($_SESSION['_auth_sql'][$this->_ns]['remote_ip']) || $_SESSION['_auth_sql'][$this->_ns]['remote_ip'] != getRemoteAddr()) {
    669669                if ($this->getParam('match_remote_ip') && !$this->get('match_remote_ip_exempt') && !$user_in_trusted_network) {
    670670                    // There are three cases when a remote IP match will be the cause of a session termination:
     
    679679            $app->logMsg(sprintf('User_id %s (%s) session expired: %s', $this->get('user_id'), $this->get('username'), join(', ', $expire_reasons)), LOG_INFO, __FILE__, __LINE__);
    680680        } else {
    681             $app->logMsg('No authenticated token in _SESSION', LOG_DEBUG, __FILE__, __LINE__);
     681            $app->logMsg('Session is not authenticated', LOG_DEBUG, __FILE__, __LINE__);
    682682        }
    683683
     
    943943        switch ($hash_type) {
    944944        case self::ENCRYPT_CRYPT :
    945             return $this->encryptPassword($password, $encrypted_password) == $encrypted_password;
     945            return $this->encryptPassword($password, $encrypted_password, $hash_type) == $encrypted_password;
    946946
    947947        case self::ENCRYPT_PLAINTEXT :
     
    950950        case self::ENCRYPT_SHA1 :
    951951        case self::ENCRYPT_SHA1_HARDENED :
    952         default :
    953             return $this->encryptPassword($password) == $encrypted_password;
     952            return $this->encryptPassword($password, $encrypted_password, $hash_type) == $encrypted_password;
    954953
    955954        case self::ENCRYPT_PASSWORD_BCRYPT :
    956955        case self::ENCRYPT_PASSWORD_DEFAULT :
    957956            return password_verify($password, $encrypted_password);
    958         }
    959 
    960         $app->logMsg(sprintf('Unknown hash type: %s', $hash_type), LOG_WARNING, __FILE__, __LINE__);
    961         return false;
     957
     958        default :
     959            $app->logMsg(sprintf('Unknown hash type: %s', $hash_type), LOG_WARNING, __FILE__, __LINE__);
     960            return false;
     961        }
     962
    962963    }
    963964
  • trunk/lib/Prefs.inc.php

    r526 r541  
    8787        'user_id' => null,
    8888
    89         // How long before we force a reload of the persistent prefs data? 3600 = once every hour.
    90         'load_timeout' => 3600,
     89        // How long before we force a reload of the persistent prefs data? 300 = every five minutes.
     90        'load_timeout' => 300,
    9191
    9292        // Name of database table to store prefs.
  • trunk/lib/Utilities.inc.php

    r534 r541  
    215215* @access   public
    216216* @param    string  $text   Text to search for URLs.
     217* @param    bool    $strict True to only include URLs starting with a scheme (http:// ftp:// im://), or false to include URLs starting with 'www.'.
    217218* @param    mixed   $length Number of characters to truncate URL, or NULL to disable truncating.
    218219* @param    string  $delim  Delimiter to append, indicate truncation.
    219220* @return   string          Same input text, but URLs hyperlinked.
    220221* @author   Quinn Comendant <quinn@strangecode.com>
    221 * @version  1.0
     222* @version  2.0
    222223* @since    22 Mar 2015 23:29:04
    223224*/
    224 function hyperlinkTxt($text, $length=null, $delim='
')
    225 {
    226     return preg_replace_callback(
    227         // Inspired by @stephenhay's regex from https://mathiasbynens.be/demo/url-regex
    228         // Here we capture the full URL into the first match and only the first X characters into the second match.
    229         sprintf('@\b(?<!")(?<!\')(?<!=)(((?:https?|s?ftps?)://[^\s/$.?#].[^\s]{0,%s})[^\s]*)@iS', $length),
    230         // Use an anonymous function to decide when to append the delim.
    231         // Also encode special chars with oTxt().
    232         function ($m) use ($length, $delim) {
    233             if (is_null($length) || $m[1] == $m[2]) {
    234                 // If not truncating, or URL was not truncated.
    235                 return sprintf('<a href="%s">%s</a>', oTxt($m[1]), oTxt($m[1]));
    236             } else {
    237                 // Truncated URL.
    238                 return sprintf('<a href="%s">%s%s</a>', oTxt($m[1]), oTxt(trim($m[2])), $delim);
    239             }
    240         },
    241         $text
     225function hyperlinkTxt($text, $strict=false, $length=null, $delim='
')
     226{
     227    // Capture the full URL into the first match and only the first X characters into the second match.
     228    // This will match URLs not preceeded by " ' or = (URLs inside an attribute) or ` (Markdown quoted) or double-scheme (http://http://www.asdf.com)
     229    // Valid URL characters: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=
     230    $regex = '@
     231        \b                              # Start with a word-boundary.
     232        (?<!"|\'|=|>|`|[\w-]{2}://)     # Negative look-behind to exclude URLs already in <a> tag, Markdown quoted, or double SCHEME://
     233        (                               # Begin match 1
     234            (                           # Begin match 2
     235                (?:[\w-]{2,}://%s)      # URL starts with SCHEME:// or www. (if strict = false)
     236                [^\s/$.?#]+             # Any domain-valid characters
     237                \.                      # At least one point
     238                [^\s"`<>]{1,%s}         # Match 2 is limited to a maximum of LENGTH valid URL characters
     239            )
     240            [^\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/277303
     242        )
     243        @Suxi
     244    ';
     245    $regex = sprintf($regex,
     246        ($strict ? '' : '|www\.'), // Strict=false allows URLs beginning with www.
     247        $length,
     248        ($strict ? '' : '?!.,:;)\'-') // Strict=false excludes these characters from set of the last character of URL.
    242249    );
     250
     251    // Use a callback function to decide when to append the delim.
     252    // Also encode special chars with oTxt().
     253    return preg_replace_callback($regex, function ($m) use ($length, $delim) {
     254        $url = $m[1];
     255        $truncated_url = $m[2];
     256        $absolute_url = preg_replace('!^www\.!', 'http://www.', $url);
     257        if (is_null($length) || $url == $truncated_url) {
     258            // If not truncating, or URL was not truncated.
     259            $display_url = preg_replace('!^[\w-]{2,}://!', '', $url);
     260            return sprintf('<a href="%s">%s</a>', oTxt($absolute_url), $display_url);
     261        } else {
     262            // Truncated URL.
     263            $display_url = preg_replace('!^[\w-]{2,}://!', '', trim($truncated_url));
     264            return sprintf('<a href="%s">%s%s</a>', oTxt($absolute_url), $display_url, $delim);
     265        }
     266    }, $text);
    243267}
    244268
     
    452476function URLSlug($str)
    453477{
    454     $slug = preg_replace(array('/[^\w]+/', '/^-+|-+$/'), array('-', ''), $str);
     478    $slug = preg_replace(array('/\W+/u', '/^-+|-+$/'), array('-', ''), $str);
    455479    $slug = strtolower($slug);
    456480    return $slug;
  • trunk/tests/AppTest.php

    r479 r541  
    112112    function test_printraisedmessages()
    113113    {
     114        $app =& App::getInstance();
    114115        ob_start();
    115116        $this->test_raisemsg();  //had to add this line for phpunit ver. 3.7 ///
    116         $app =& App::getInstance();
    117117        $app->printraisedmessages();
    118118        $result = ob_get_clean();
     
    145145    {
    146146        $app =& App::getInstance();
     147        $app->setParam(array('session_use_trans_sid' => true));
    147148        ob_start();
    148149        $app->printhiddensession();
  • trunk/tests/AuthSQLTest.php

    r479 r541  
    7171        ");
    7272        $_SESSION = AuthSQLTest::$shared_session;
     73
     74        // Sessions require client IP addr.
     75        $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
    7376    }
    7477
     
    206209    function test_generatepassword()
    207210    {
    208         $result = $this->Auth_SQL->generatepassword('xCVcvd');
    209         $this->assertRegExp('/[bcdfghjklmnprstvwxzBCDFGHJKLMNPRSTVWXZaeiouyAEIOUY0123456789!@#%&*-=+.?][bcdfghjklmnprstvwxzBCDFGHJKLMNPRSTVWXZ][aeiouyAEIOUY][bcdfghjklmnprstvwxz][aeiouy][0123456789]/', $result, 'Generated password does not match intended pattern');
     211        $result = $this->Auth_SQL->generatepassword(10);
     212        $this->assertEquals(14, strlen($result));
    210213    }
    211214
    212215    function test_encryptpassword()
    213216    {
    214         $this->Auth_SQL->setParam(array('encryption_type' => Auth_SQL::ENCRYPT_MD5));
    215         $result = $this->Auth_SQL->encryptpassword('123');
     217        $result = $this->Auth_SQL->encryptpassword('123', null, Auth_SQL::ENCRYPT_MD5);
    216218        $this->assertEquals('202cb962ac59075b964b07152d234b70', $result);
    217 
    218         $this->Auth_SQL->setParam(array('encryption_type' => Auth_SQL::ENCRYPT_MD5_HARDENED));
    219         $result = $this->Auth_SQL->encryptpassword('123');
    220         $this->assertEquals('c55e4ac608a8768ecd758fab971b0646', $result);
    221 
    222         $this->Auth_SQL->setParam(array('encryption_type' => Auth_SQL::ENCRYPT_SHA1));
    223         $result = $this->Auth_SQL->encryptpassword('123');
     219        $this->assertTrue($this->Auth_SQL->verifyPassword('123', $result, Auth_SQL::ENCRYPT_MD5));
     220
     221        $result = $this->Auth_SQL->encryptpassword('123', null, Auth_SQL::ENCRYPT_MD5_HARDENED);
     222        $this->assertEquals('1f0f8d357a96eb97f24371ebf53dcaf6', $result);
     223        $this->assertTrue($this->Auth_SQL->verifyPassword('123', $result, Auth_SQL::ENCRYPT_MD5_HARDENED));
     224
     225        $result = $this->Auth_SQL->encryptpassword('123', null, Auth_SQL::ENCRYPT_SHA1);
    224226        $this->assertEquals('40bd001563085fc35165329ea1ff5c5ecbdbbeef', $result);
    225 
    226         $this->Auth_SQL->setParam(array('encryption_type' => Auth_SQL::ENCRYPT_SHA1_HARDENED));
    227         $result = $this->Auth_SQL->encryptpassword('123');
    228         $this->assertEquals('33d90af96a5928ac93cbd41fc436e8c55d2768c2', $result);
    229 
    230         $this->Auth_SQL->setParam(array('encryption_type' => Auth_SQL::ENCRYPT_PLAINTEXT));
    231         $result = $this->Auth_SQL->encryptpassword('123');
     227        $this->assertTrue($this->Auth_SQL->verifyPassword('123', $result, Auth_SQL::ENCRYPT_SHA1));
     228
     229        $result = $this->Auth_SQL->encryptpassword('123', null, Auth_SQL::ENCRYPT_SHA1_HARDENED);
     230        $this->assertEquals('1d086fcae3dd941e0f1371148502d03e96ab536f', $result);
     231        $this->assertTrue($this->Auth_SQL->verifyPassword('123', $result, Auth_SQL::ENCRYPT_SHA1_HARDENED));
     232
     233        $result = $this->Auth_SQL->encryptpassword('123', null, Auth_SQL::ENCRYPT_PLAINTEXT);
    232234        $this->assertEquals('123', $result);
    233 
    234         $this->Auth_SQL->setParam(array('encryption_type' => Auth_SQL::ENCRYPT_CRYPT));
    235         $result = $this->Auth_SQL->encryptpassword('123', 'saltstring');
    236         $this->assertEquals('saEZ6MlWYV9nQ', $result);
     235        $this->assertTrue($this->Auth_SQL->verifyPassword('123', $result, Auth_SQL::ENCRYPT_PLAINTEXT));
     236
     237        $result = $this->Auth_SQL->encryptpassword('123', 'saltstring', Auth_SQL::ENCRYPT_CRYPT);
     238        $this->assertTrue($this->Auth_SQL->verifyPassword('123', $result, Auth_SQL::ENCRYPT_CRYPT));
     239
     240        if (function_exists('password_hash')) {
     241            // Only available in PHP >= 5.5
     242            $result = $this->Auth_SQL->encryptpassword('123', 'saltstring', Auth_SQL::ENCRYPT_PASSWORD_BCRYPT);
     243            $this->assertTrue($this->Auth_SQL->verifyPassword('123', $result, Auth_SQL::ENCRYPT_PASSWORD_BCRYPT));
     244
     245            $result = $this->Auth_SQL->encryptpassword('123', 'saltstring', Auth_SQL::ENCRYPT_PASSWORD_DEFAULT);
     246            $this->assertTrue($this->Auth_SQL->verifyPassword('123', $result, Auth_SQL::ENCRYPT_PASSWORD_DEFAULT));
     247        }
    237248    }
    238249
     
    241252        $db =& DB::getInstance();
    242253
    243         $this->Auth_SQL->setParam(array('encryption_type' => Auth_SQL::ENCRYPT_SHA1_HARDENED));
     254        $this->Auth_SQL->setParam(array('hash_type' => Auth_SQL::ENCRYPT_SHA1_HARDENED));
    244255        $this->Auth_SQL->setpassword(null, '123');
    245256        $qid = $db->query("
     
    248259        ");
    249260        list($pass) = mysql_fetch_row($qid);
    250         $this->assertEquals('33d90af96a5928ac93cbd41fc436e8c55d2768c2', $pass);
     261        $this->assertEquals('1d086fcae3dd941e0f1371148502d03e96ab536f', $pass);
    251262    }
    252263
  • trunk/tests/LockTest.php

    r479 r541  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    3737
    3838    function setUp()
    39     {   
     39    {
    4040        require dirname(__FILE__) . '/_config.inc.php';
    4141        require_once '../lib/Lock.inc.php';
     
    7171            )
    7272        ");
     73
     74        // Sessions require client IP addr.
     75        $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     76
    7377        $this->Auth_SQL->login('testuser', 'testpass');
    7478
     
    8791    {
    8892        $db =& DB::getInstance();
    89    
     93
    9094        unset($this->Lock);
    9195        unset($this->Auth_SQL);
  • trunk/tests/UtilitiesTest.php

    r468 r541  
    11<?php
    2 /// FIXME: Tests not implemented.
    3 return;
    4 
    52/**
    63 * The Strangecode Codebase - a general application development framework for PHP
    74 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    85 * Copyright 2001-2012 Strangecode, LLC
    9  * 
     6 *
    107 * This file is part of The Strangecode Codebase.
    118 *
     
    1411 * Free Software Foundation, either version 3 of the License, or (at your option)
    1512 * any later version.
    16  * 
     13 *
    1714 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1815 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1916 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    2017 * details.
    21  * 
     18 *
    2219 * You should have received a copy of the GNU General Public License along with
    2320 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    3633class UtilitiesTest extends PHPUnit_Framework_TestCase {
    3734
    38     var $Utilities;
    39 
    40     function UtilitiesTest($name)
    41     {
    42         $this->PHPUnit_Framework_TestCase($name);
    43     }
    44 
    4535    function setUp()
    4636    {
     37        define('_CLI', true);
    4738        require dirname(__FILE__) . '/_config.inc.php';
    4839        require_once '../lib/Utilities.inc.php';
    49         $this->Utilities =& new Utilities(PARAM);
     40        // $this->Utilities =& new Utilities(PARAM);
    5041    }
    5142
    5243    function tearDown()
    5344    {
    54         unset($this->Utilities);
     45        $app =& App::getInstance();
     46        $app->stop();
     47    }
     48
     49    function test_hyperlinkTxt()
     50    {
     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>? ',
     55            ' www.asdf.com/?x=y+z ' => ' <a href="http://www.asdf.com/?x=y+z">www.asdf.com/?x=y+z</a> ',
     56            ' www.asdf.com/?x=y+ ' => ' <a href="http://www.asdf.com/?x=y+">www.asdf.com/?x=y+</a> ',
     57            ' www.asdf.com/?x= ' => ' <a href="http://www.asdf.com/?x=">www.asdf.com/?x=</a> ',
     58            ' www.asdf.com/?x ' => ' <a href="http://www.asdf.com/?x">www.asdf.com/?x</a> ',
     59            ' www.asdf.com/?❀=🔥 ' => ' <a href="http://www.asdf.com/?❀=🔥">www.asdf.com/?❀=🔥</a> ',
     60            ' www.asdf.com? ' => ' <a href="http://www.asdf.com">www.asdf.com</a>? ',
     61            ' www.asdf.com! ' => ' <a href="http://www.asdf.com">www.asdf.com</a>! ',
     62            ' www.asdf.com. ' => ' <a href="http://www.asdf.com">www.asdf.com</a>. ',
     63            ' `www.asdf.com` ' => ' `www.asdf.com` ',
     64            ' "www.asdf.com" ' => ' "www.asdf.com" ',
     65            ' <www.asdf.com> ' => ' <<a href="http://www.asdf.com">www.asdf.com</a>> ',
     66            ' <http://www.asdf.com> ' => ' <<a href="http://www.asdf.com">www.asdf.com</a>> ',
     67            ' (http://www.asdf.com) ' => ' (<a href="http://www.asdf.com">www.asdf.com</a>) ',
     68            ' (URL: http://www.asdf.com#1) ' => ' (URL: <a href="http://www.asdf.com#1">www.asdf.com#1</a>) ',
     69            ' <a href="http://www.example.com/">Click Here</a> ' => ' <a href="http://www.example.com/">Click Here</a> ',
     70            ' <a href="http://www.example.com/">http://www.example.com/</a> ' => ' <a href="http://www.example.com/">http://www.example.com/</a> ',
     71            ' <a href=http://www.example.com/>http://www.example.com/</a> ' => ' <a href=http://www.example.com/>http://www.example.com/</a> ',
     72            ' <a href=\'http://www.example.com/\' >http://www.example.com/</a> ' => ' <a href=\'http://www.example.com/\' >http://www.example.com/</a> ',
     73            ' http://foo.com/blah_blah ' => ' <a href="http://foo.com/blah_blah">foo.com/blah_blah</a> ',
     74            ' http://foo.com/blah_blah/ ' => ' <a href="http://foo.com/blah_blah/">foo.com/blah_blah/</a> ',
     75            ' http://foo.com/blah_blah_(wikipedia) ' => ' <a href="http://foo.com/blah_blah_(wikipedia">foo.com/blah_blah_(wikipedia</a>) ',
     76            ' http://foo.com/blah_blah_(wikipedia)_(again) ' => ' <a href="http://foo.com/blah_blah_(wikipedia)_(again">foo.com/blah_blah_(wikipedia)_(again</a>) ',
     77            ' http://www.example.com/wpstyle/?p=364 ' => ' <a href="http://www.example.com/wpstyle/?p=364">www.example.com/wpstyle/?p=364</a> ',
     78            ' https://www.example.com/foo/?bar=baz&inga=42&quux ' => ' <a href="https://www.example.com/foo/?bar=baz&amp;inga=42&amp;quux">www.example.com/foo/?bar=baz&inga=42&quux</a> ',
     79            ' http://✪df.ws/123 ' => ' <a href="http://✪df.ws/123">✪df.ws/123</a> ',
     80            ' 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> ',
     82            ' 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> ',
     84            ' 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> ',
     86            ' 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://➡.ws/äš¹ ' => ' <a href="http://➡.ws/äš¹">➡.ws/äš¹</a> ',
     91            ' http://⌘.ws ' => ' <a href="http://⌘.ws">⌘.ws</a> ',
     92            ' http://⌘.ws/ ' => ' <a href="http://⌘.ws/">⌘.ws/</a> ',
     93            ' http://foo.com/blah_(wikipedia)#cite-1 ' => ' <a href="http://foo.com/blah_(wikipedia)#cite-1">foo.com/blah_(wikipedia)#cite-1</a> ',
     94            ' 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            ' http://foo.com/unicode_(✪)_in_parens ' => ' <a href="http://foo.com/unicode_(✪)_in_parens">foo.com/unicode_(✪)_in_parens</a> ',
     96            ' 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> ',
     98            ' http://code.google.com/events/#&product=browser ' => ' <a href="http://code.google.com/events/#&amp;product=browser">code.google.com/events/#&product=browser</a> ',
     99            ' http://j.mp ' => ' <a href="http://j.mp">j.mp</a> ',
     100            ' ftp://foo.bar/baz ' => ' <a href="ftp://foo.bar/baz">foo.bar/baz</a> ',
     101            ' 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            ' http://Ù
     103ثال.إختؚار ' => ' <a href="http://Ù
     104ثال.إختؚار">Ù
     105ثال.إختؚار</a> ',
     106            ' http://䟋子.测试 ' => ' <a href="http://䟋子.测试">䟋子.测试</a> ',
     107            ' http://à€‰à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥€à€•à¥à€·à€Ÿ ' => ' <a href="http://à€‰à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥€à€•à¥à€·à€Ÿ">à€‰à€Šà€Ÿà€¹à€°à€£.à€ªà€°à¥€à€•à¥à€·à€Ÿ</a> ',
     108            ' http://-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com ' => ' <a href="http://-.~_!$&amp;&#039;()*+,;=:%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=✓&amp;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&amp;utf8=*">github.com/search?q=gif&utf8=*</a> ',
     116            ' https://github.com/search?q=gif&utf8=✓ ' => ' <a href="https://github.com/search?q=gif&amp;utf8=✓">github.com/search?q=gif&utf8=✓</a> ',
     117
     118            // 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> ',
     120        ];
     121        foreach ($urls as $input => $expected) {
     122            $result = hyperlinkTxt($input, false);
     123            $this->assertEquals($expected, $result, sprintf('Failed with input: %s', $input));
     124        }
    55125    }
    56126
  • trunk/tests/phpunit.xml

    r468 r541  
    3434            <file>PayPalTest.php</file>
    3535            <file>VersionTest.php</file>
     36            <file>UtilitiesTest.php</file>
    3637        </testsuite>
    3738    </testsuites>
  • trunk/tests/run_tests.sh

    r468 r541  
    3131# Config options go in phpunit.xml
    3232# phpunit --tap | grep -v '^ok '
    33 phpunit --stderr
     33phpunit --stderr || echo "Something went wrong (if there is no output above, check the php_error_log)";
Note: See TracChangeset for help on using the changeset viewer.