Добавлено экранирование # символа в QR коде

This commit is contained in:
ErickSkrauch 2018-01-28 13:34:27 +03:00
parent 01850bb2d6
commit 013ddd1b1b

View File

@ -22,7 +22,7 @@ class TwoFactorAuthInfo extends BaseAccountForm {
$provisioningUri = $this->getTotp()->getProvisioningUri();
return [
'qr' => 'data:image/svg+xml,' . trim($this->drawQrCode($provisioningUri)),
'qr' => $this->buildDataImage($this->drawQrCode($provisioningUri)),
'uri' => $provisioningUri,
'secret' => $this->getAccount()->otp_secret,
];
@ -41,6 +41,14 @@ class TwoFactorAuthInfo extends BaseAccountForm {
return $writer->writeString($content, Encoder::DEFAULT_BYTE_MODE_ECODING, ErrorCorrectionLevel::H);
}
private function buildDataImage(string $svg) {
$svg = trim($svg);
// https://stackoverflow.com/a/30733736/5184751
$svg = str_replace('#', '%23', $svg);
return 'data:image/svg+xml,' . $svg;
}
/**
* @param int $length
* @throws ThisShouldNotHappenException