Skip to content

Commit

Permalink
change error thrown for null byte issues (#1813)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavdid-stripe authored Feb 5, 2025
1 parent 067658d commit 931c31f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ private function _requestRaw($method, $url, $params, $headers, $apiMode, $usage)
// for some reason, PHP users will sometimes include null bytes in their paths, which leads to cryptic server 400s.
// we'll be louder about this to help catch issues earlier.
if (false !== \strpos($absUrl, "\0") || false !== \strpos($absUrl, '%00')) {
throw new Exception\BadMethodCallException("URLs may not contain null bytes ('\\0'); double check any IDs you're including with the request.");
throw new Exception\InvalidRequestException("URLs may not contain null bytes ('\\0'); double check any IDs you're including with the request.");
}

$requestStartMs = Util\Util::currentTimeMillis();
Expand Down
4 changes: 2 additions & 2 deletions tests/Stripe/ApiRequestorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,15 +729,15 @@ public function testIsDisabled()

public function testRaisesForNullBytesInResourceMethod()
{
$this->expectException(\Stripe\Exception\BadMethodCallException::class);
$this->expectException(\Stripe\Exception\InvalidRequestException::class);
$this->compatExpectExceptionMessageMatches('#null byte#');

Charge::retrieve("abc_123\0");
}

public function testRaisesForNullBytesInRawRequest()
{
$this->expectException(\Stripe\Exception\BadMethodCallException::class);
$this->expectException(\Stripe\Exception\InvalidRequestException::class);
$this->compatExpectExceptionMessageMatches('#null byte#');

$client = new BaseStripeClient([
Expand Down

0 comments on commit 931c31f

Please sign in to comment.