Skip to content

Commit 2a100b7

Browse files
committed
fix: wrong encoding on tel: href
1 parent 1592e14 commit 2a100b7

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

EMS/common-bundle/src/Helper/Text/Encoder.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,12 @@ public function htmlEncodePii(string $text): string
3939

4040
/**
4141
* Detect telephone information using the '"tel:xxx"' pattern
42-
* <a href="tel:02/123.45.23">02/123.45.23</a>.
42+
* <a href="tel:+3221234523">02/123.45.23</a>.
4343
*/
4444
private function encodePhone(string $text): string
4545
{
46-
$telRegex = '/(?P<tel>"tel:.*")/i';
47-
48-
$encodedText = \preg_replace_callback($telRegex, fn ($match) => $this->htmlEncode($match['tel']), $text);
46+
$telRegex = '/"tel:(?P<tel>.*)"/i';
47+
$encodedText = \preg_replace_callback($telRegex, fn ($match) => \sprintf('"tel:%s"', $this->htmlEncode($match['tel'])), $text);
4948

5049
if (null === $encodedText) {
5150
return $text;

EMS/common-bundle/tests/Unit/Helper/Text/EncoderAiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ public function testHtmlEncodePiiEncodesPhoneNumbers(): void
6666
$textWithPhone = 'Call me at <a href="tel:123-456-7890">123-456-7890</a>';
6767
$encoded = $this->encoder->htmlEncodePii($textWithPhone);
6868

69-
$this->assertStringContainsString('&#34;&#116;&#101;&#108;&#58;&#49;&#50;&#51;&#45;&#52;&#53;&#54;&#45;&#55;&#56;&#57;&#48;&#34;', $encoded);
69+
$this->assertEquals('Call me at <a href="tel:&#49;&#50;&#51;&#45;&#52;&#53;&#54;&#45;&#55;&#56;&#57;&#48;">123-456-7890</a>', $encoded);
7070
}
7171
}

EMS/common-bundle/tests/Unit/Helper/Text/EncoderTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public static function piiProvider(): array
5757
['é', 'é'],
5858
['<', '<'],
5959
['mailto:[email protected]', \sprintf('mailto:%s', $email)],
60-
['"tel:02/345.67.89"', '&#34;&#116;&#101;&#108;&#58;&#48;&#50;&#47;&#51;&#52;&#53;&#46;&#54;&#55;&#46;&#56;&#57;&#34;'],
60+
['<a href="mailto:[email protected]">[email protected]</a>', \sprintf('<a href="mailto:%s">%s</a>', $email, $email)],
61+
['"tel:02/345.67.89"', '"tel:&#48;&#50;&#47;&#51;&#52;&#53;&#46;&#54;&#55;&#46;&#56;&#57;"'],
62+
['<a href="tel:+3221234523">02/123.45.23</a>', '<a href="tel:&#43;&#51;&#50;&#50;&#49;&#50;&#51;&#52;&#53;&#50;&#51;">02/123.45.23</a>'],
6163
['<span class="pii">example</span>', $example],
6264
];
6365
}

0 commit comments

Comments
 (0)