diff --git a/src/OTP.php b/src/OTP.php index 4765d49..7e68dfc 100644 --- a/src/OTP.php +++ b/src/OTP.php @@ -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', diff --git a/tests/TOTPTest.php b/tests/TOTPTest.php index d110940..c868a75 100644 --- a/tests/TOTPTest.php +++ b/tests/TOTPTest.php @@ -109,6 +109,21 @@ public function getProvisioningUri(): void ); } + /** + * @test + */ + public function getProvisioningUriWithNonDefaultArgSeperator(): void + { + $otp = self::createTOTP(6, 'sha1', 30); + + ini_set('arg_separator.output', '&'); + + static::assertSame( + 'otpauth://totp/My%20Project%3Aalice%40foo.bar?issuer=My%20Project&secret=JDDK4U6G3BJLEZ7Y', + $otp->getProvisioningUri() + ); + } + /** * @param positive-int $timestamp * @param positive-int $period