From e87f91c6d83438c7e792902a4fb15a5ca6808162 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 20 Mar 2016 00:06:49 +0900 Subject: [PATCH 1/7] Fix Travis errors on PHP 5.3 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 402dc8ce2..04ec79659 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,9 @@ before_script: - if [[ $TRAVIS_PHP_VERSION == "5.4" ]]; then wget http://codeception.com/releases/2.0.16/codecept.phar; fi - if [[ ! -f codecept.phar ]]; then wget http://codeception.com/releases/2.1.6/codecept.phar; fi script: -- if [[ -f codecept.phar ]]; then php codecept.phar build; fi -- if [[ $TRAVIS_PHP_VERSION == "hhvm" ]]; then php codecept.phar run -d --fail-fast --env travis --skip install; fi -- if [[ $TRAVIS_PHP_VERSION != "hhvm" ]]; then php codecept.phar run -d --fail-fast --env travis; fi +- if [[ -s codecept.phar ]]; then php codecept.phar build; fi +- if [[ -s codecept.phar && $TRAVIS_PHP_VERSION == "hhvm" ]]; then php codecept.phar run -d --fail-fast --env travis --skip install; fi +- if [[ -s codecept.phar && $TRAVIS_PHP_VERSION != "hhvm" ]]; then php codecept.phar run -d --fail-fast --env travis; fi - grunt lint notifications: email: false From 5b5c785b19ff14d89662a7f5dc52cf815329ab5a Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 20 Mar 2016 00:32:31 +0900 Subject: [PATCH 2/7] Do not simply exit on DB connection error --- classes/db/DBMysql.class.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/classes/db/DBMysql.class.php b/classes/db/DBMysql.class.php index 1b5264ed8..a8f321c64 100644 --- a/classes/db/DBMysql.class.php +++ b/classes/db/DBMysql.class.php @@ -67,7 +67,8 @@ class DBMysql extends DB $result = @mysql_connect($connection['host'], $connection['user'], $connection['pass']); if(!$result) { - exit('Unable to connect to DB.'); + $this->setError(-1, 'Unable to connect to DB.'); + return; } if(mysql_error()) @@ -164,7 +165,8 @@ class DBMysql extends DB { if(!$connection) { - exit('Rhymix cannot handle DB connection.'); + $this->setError(-1, 'Unable to connect to DB.'); + return false; } // Run the query statement $result = @mysql_query($query, $connection); From 770644d1144b01cb47435846e95487849bfcd90b Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 20 Mar 2016 00:45:20 +0900 Subject: [PATCH 3/7] Improve error handling in MySQL/MySQLi DB drivers --- classes/context/Context.class.php | 6 +++++- classes/db/DBMysqli.class.php | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index cc21eef86..3058d3a3c 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -1063,7 +1063,11 @@ class Context */ public static function convertEncodingStr($str) { - if(!$str) return null; + if (!$str || utf8_check($str)) + { + return $str; + } + $obj = new stdClass; $obj->str = $str; $obj = self::convertEncoding($obj); diff --git a/classes/db/DBMysqli.class.php b/classes/db/DBMysqli.class.php index 8c425be45..ef8f845ba 100644 --- a/classes/db/DBMysqli.class.php +++ b/classes/db/DBMysqli.class.php @@ -80,8 +80,8 @@ class DBMysqli extends DBMysql { if ($connection === null) { - debug_print_backtrace(); - exit; + $this->setError(-1, 'Unable to connect to DB.'); + return false; } if($this->use_prepared_statements == 'Y') { From 787bcd658bbf8c539d41d2e832a8a131c8059ffd Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 20 Mar 2016 00:52:17 +0900 Subject: [PATCH 4/7] Improve error handling in PBKDF2 hashing routine --- common/framework/password.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/framework/password.php b/common/framework/password.php index bac5e284f..caf9ef49a 100644 --- a/common/framework/password.php +++ b/common/framework/password.php @@ -218,7 +218,7 @@ class Password { $salt = Security::getRandom(12, 'alnum'); $hash_algorithm = 'sha512'; - $iterations = pow(2, self::getWorkFactor() + 5); + $iterations = intval(pow(2, self::getWorkFactor() + 5)) ?: 16384; $key_length = 24; } else @@ -226,7 +226,7 @@ class Password $parts = explode(':', $salt); $salt = $parts[2]; $hash_algorithm = $parts[0]; - $iterations = $parts[1]; + $iterations = intval($parts[1], 10); $key_length = strlen(base64_decode($parts[3])); } return self::pbkdf2($hashchain, $salt, $hash_algorithm, $iterations, $key_length); From eb1c6e33e68dcd15653c433fe64dedcf55f408ae Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 20 Mar 2016 09:54:10 +0900 Subject: [PATCH 5/7] Improve dotfile handling in Storage::readDirectory() on HHVM --- common/framework/storage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/framework/storage.php b/common/framework/storage.php index e8de90d7b..5e8d5e475 100644 --- a/common/framework/storage.php +++ b/common/framework/storage.php @@ -339,7 +339,7 @@ class Storage try { - $iterator = new \FilesystemIterator($dirname, \FilesystemIterator::CURRENT_AS_PATHNAME); + $iterator = new \FilesystemIterator($dirname, \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS); } catch (\UnexpectedValueException $e) { From 0bbe4ac07f7a701bf33a3c9bf5c5e033ac72b4e3 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 20 Mar 2016 10:04:03 +0900 Subject: [PATCH 6/7] Fix timer tests on HHVM --- tests/unit/framework/TimerTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/unit/framework/TimerTest.php b/tests/unit/framework/TimerTest.php index 1c9783c0d..c5c4bc2ea 100644 --- a/tests/unit/framework/TimerTest.php +++ b/tests/unit/framework/TimerTest.php @@ -38,11 +38,9 @@ class TimerTest extends \Codeception\TestCase\Test function testMultipleTimers() { $t1 = Rhymix\Framework\Timer::start('timer1'); - usleep(5000); + usleep(10000); $t2 = Rhymix\Framework\Timer::start('timer2'); - usleep(1000); $t3 = Rhymix\Framework\Timer::stop('timer1'); - usleep(2000); $t4 = Rhymix\Framework\Timer::stop('timer2'); $this->assertGreaterThanOrEqual($t1, $t2); @@ -52,7 +50,7 @@ class TimerTest extends \Codeception\TestCase\Test function testTimerFormat() { $t1 = Rhymix\Framework\Timer::start(); - usleep(1000); + usleep(10000); $t2 = Rhymix\Framework\Timer::stopFormat(); $this->assertRegexp('/^[0-9\.,]+ms$/', $t2); From 456ec87447b50e8c398b722772a781a1cb8c1fe3 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Sun, 20 Mar 2016 13:43:00 +0900 Subject: [PATCH 7/7] Fix DB connection during unit tests on HHVM --- tests/unit/functions/LegacyTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/functions/LegacyTest.php b/tests/unit/functions/LegacyTest.php index 5bb693d56..48ffe6c7f 100644 --- a/tests/unit/functions/LegacyTest.php +++ b/tests/unit/functions/LegacyTest.php @@ -22,7 +22,7 @@ class LegacyTest extends \Codeception\TestCase\Test public function testGetNextSequence() { - if (!file_exists(\RX_BASEDIR . 'files/config/config.php')) + if (!DB::getInstance()->isConnected()) { return; }