Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim spaces when parsing php.ini disablefunctions #1015

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion lib/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,27 @@ 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
* @param mixed $disableFunctionsOutput
*
* @return bool
*/
private static function _isDisabled($disableFunctionsOutput, $functionName)
{
$disabledFunctions = \explode(',', $disableFunctionsOutput);
foreach ($disabledFunctions as $disabledFunction) {
if (\trim($disabledFunction) === $functionName) {
return true;
}
}

return false;
}

/**
* @static
*
Expand All @@ -268,7 +289,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();
Expand Down
34 changes: 34 additions & 0 deletions tests/Stripe/ApiRequestorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,38 @@ 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::assertFalse($result);

$result = $method->invoke(null, 'exec', 'php_uname');
static::assertFalse($result);

$result = $method->invoke(null, 'exec, procopen', 'php_uname');
static::assertFalse($result);

$result = $method->invoke(null, 'exec,procopen', 'php_uname');
static::assertFalse($result);

$result = $method->invoke(null, 'exec,php_uname', 'php_uname');
static::assertTrue($result);

$result = $method->invoke(null, 'exec, php_uname', 'php_uname');
static::assertTrue($result);

$result = $method->invoke(null, 'php_uname, exec', 'php_uname');
static::assertTrue($result);

$result = $method->invoke(null, 'procopen,php_uname, exec', 'php_uname');
static::assertTrue($result);

$result = $method->invoke(null, 'procopen, php_uname, exec', 'php_uname');
static::assertTrue($result);
}
}