Skip to content

Commit

Permalink
fix(tel-link): handle non-digit characters
Browse files Browse the repository at this point in the history
  • Loading branch information
evolkmann committed Apr 11, 2024
1 parent ab7d0f9 commit 3b3a766
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/UrlHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class UrlHelpers {

static function telLink(string $phoneNumber): string
{
return 'tel:' . str_replace(' ', '', $phoneNumber);
return 'tel:' . preg_replace('/[^\d+]/', '', $phoneNumber);
}

static function mailtoLink(string $email): string
Expand Down
21 changes: 21 additions & 0 deletions tests/UrlHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ public function testTelLink(): void
$this->assertSame($res, 'tel:12345');
}

public function testTelLinkWhitespace(): void
{
$phone = '0123 4567 8910';
$res = UrlHelpers::telLink($phone);
$this->assertSame($res, 'tel:012345678910');
}

public function testTelLinkCharacters(): void
{
$phone = '0123 / 4567 8910';
$res = UrlHelpers::telLink($phone);
$this->assertSame($res, 'tel:012345678910');
}

public function testTelLinkCountryPrefix(): void
{
$phone = '+49 123 / 4567 8910';
$res = UrlHelpers::telLink($phone);
$this->assertSame($res, 'tel:+4912345678910');
}

public function testMailtoLink(): void
{
$mail = '[email protected]';
Expand Down

0 comments on commit 3b3a766

Please sign in to comment.