Skip to content

Commit

Permalink
Trim spaces when parsing php.ini disablefunctions
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Sep 21, 2020
1 parent 51e95c5 commit fa93c77
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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();
Expand Down
33 changes: 33 additions & 0 deletions tests/Stripe/ApiRequestorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit fa93c77

Please sign in to comment.