Skip to content

Commit

Permalink
explixitly set arg_separator for generateURI (#210)
Browse files Browse the repository at this point in the history
We cannot rely on arg_separator.output to be set to it's default '&',
therefore we explicitly set it here.

Signed-off-by: Daniel Ziegenberg <[email protected]>
  • Loading branch information
ziegenberg authored Apr 14, 2024
1 parent 9a15690 commit 5b5b047
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/OTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected function generateURI(string $type, array $options): string
$this->hasColon($label) === false || throw new InvalidArgumentException('Label must not contain a colon.');
$options = [...$options, ...$this->getParameters()];
$this->filterOptions($options);
$params = str_replace(['+', '%7E'], ['%20', '~'], http_build_query($options));
$params = str_replace(['+', '%7E'], ['%20', '~'], http_build_query($options, arg_separator: '&'));

return sprintf(
'otpauth://%s/%s?%s',
Expand Down
15 changes: 15 additions & 0 deletions tests/TOTPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ public function getProvisioningUri(): void
);
}

/**
* @test
*/
public function getProvisioningUriWithNonDefaultArgSeperator(): void
{
$otp = self::createTOTP(6, 'sha1', 30);

ini_set('arg_separator.output', '&amp;');

static::assertSame(
'otpauth://totp/My%20Project%3Aalice%40foo.bar?issuer=My%20Project&secret=JDDK4U6G3BJLEZ7Y',
$otp->getProvisioningUri()
);
}

/**
* @param positive-int $timestamp
* @param positive-int $period
Expand Down

0 comments on commit 5b5b047

Please sign in to comment.