Skip to content

Commit

Permalink
explixitly set arg_separator for generateURI
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 committed Apr 14, 2024
1 parent 3380f38 commit ab3a5f1
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -98,7 +98,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
13 changes: 13 additions & 0 deletions tests/TOTPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ 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()
);
}

#[Test]
#[DataProvider('dataRemainingTimeBeforeExpiration')]
/**
Expand Down

0 comments on commit ab3a5f1

Please sign in to comment.