Skip to content

Commit

Permalink
Merge pull request #1015 from stripe/richardm-forgive-spaces-in-disab…
Browse files Browse the repository at this point in the history
…le-functions

Trim spaces when parsing php.ini disablefunctions
  • Loading branch information
richardm-stripe authored Sep 22, 2020
2 parents 7b96e76 + 850ccad commit 013b99c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
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);
}
}

0 comments on commit 013b99c

Please sign in to comment.