From fa93c77a85b23444e69765d57cd4203ce138caa3 Mon Sep 17 00:00:00 2001 From: Richard Marmorstein Date: Mon, 21 Sep 2020 14:23:22 -0400 Subject: [PATCH] Trim spaces when parsing php.ini disablefunctions --- lib/ApiRequestor.php | 21 +++++++++++++++++++- tests/Stripe/ApiRequestorTest.php | 33 +++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/lib/ApiRequestor.php b/lib/ApiRequestor.php index 0328112b85..4d0a488a78 100644 --- a/lib/ApiRequestor.php +++ b/lib/ApiRequestor.php @@ -255,6 +255,25 @@ private static function _formatAppInfo($appInfo) return null; } + /** + * @static + * + * @param string $disabledFunctionsOutput - String value of the 'disable_function' setting, as output by \ini_get('disable_functions') + * @param string $functionName - Name of the function we are interesting in seeing whether or not it is disabled. + * + * @return bool + */ + private static function _isDisabled($disableFunctionsOutput, $functionName) + { + $disabledFunctions = \explode(",", $disableFunctionsOutput); + foreach ($disabledFunctions as $disabledFunction) { + if (\trim($disabledFunction) === $functionName) { + return true; + } + } + return false; + } + /** * @static * @@ -268,7 +287,7 @@ private static function _defaultHeaders($apiKey, $clientInfo = null) $uaString = 'Stripe/v1 PhpBindings/' . Stripe::VERSION; $langVersion = \PHP_VERSION; - $uname_disabled = \in_array('php_uname', \explode(',', \ini_get('disable_functions')), true); + $uname_disabled = static::_isDisabled(\ini_get('disable_functions'), 'php_uname'); $uname = $uname_disabled ? '(disabled)' : \php_uname(); $appInfo = Stripe::getAppInfo(); diff --git a/tests/Stripe/ApiRequestorTest.php b/tests/Stripe/ApiRequestorTest.php index db741d577c..c569b29667 100644 --- a/tests/Stripe/ApiRequestorTest.php +++ b/tests/Stripe/ApiRequestorTest.php @@ -576,4 +576,37 @@ public function testHeaderStripeAccountRequestOptions() ); Charge::create([], ['stripe_account' => 'acct_123']); } + + public function testIsDisabled() { + $reflector = new \ReflectionClass(\Stripe\ApiRequestor::class); + $method = $reflector->getMethod('_isDisabled'); + $method->setAccessible(true); + + $result = $method->invoke(null, "", "php_uname"); + static::assertSame(false, $result); + + $result = $method->invoke(null, "exec", "php_uname"); + static::assertSame(false, $result); + + $result = $method->invoke(null, "exec, procopen", "php_uname"); + static::assertSame(false, $result); + + $result = $method->invoke(null, "exec,procopen", "php_uname"); + static::assertSame(false, $result); + + $result = $method->invoke(null, "exec,php_uname", "php_uname"); + static::assertSame(true, $result); + + $result = $method->invoke(null, "exec, php_uname", "php_uname"); + static::assertSame(true, $result); + + $result = $method->invoke(null, "php_uname, exec", "php_uname"); + static::assertSame(true, $result); + + $result = $method->invoke(null, "procopen,php_uname, exec", "php_uname"); + static::assertSame(true, $result); + + $result = $method->invoke(null, "procopen, php_uname, exec", "php_uname"); + static::assertSame(true, $result); + } }