From 434784ad023b92451b55ec3edd674a455716038b Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Tue, 13 Jan 2026 11:17:47 +0100 Subject: [PATCH 01/10] IBX-10978: Added tel/mailto options to urlType --- .../FixUrlProtocolListener.php | 58 +++++++++++++++++++ src/lib/Form/Type/FieldType/UrlFieldType.php | 2 + 2 files changed, 60 insertions(+) create mode 100644 src/lib/Form/EventSubscriber/FixUrlProtocolListener.php diff --git a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php new file mode 100644 index 00000000..899f7673 --- /dev/null +++ b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php @@ -0,0 +1,58 @@ +defaultProtocol = $defaultProtocol; + } + + public function onSubmit(FormEvent $event) + { + $data = $event->getData(); + if (null === $this->defaultProtocol || empty($data) || !\is_string($data)) { + return; + } + + $protocol = explode(':', $data)[0]; + if ($this->hasAuthority($protocol) && preg_match('~^(?:[/.]|[\w+.-]+://|[^:/?@#]++@)~', $data)) { + return; + } + + if (!$this->hasAuthority($protocol) && preg_match('~^(?:[/.]|[\w+.-]+:|[^:/?@#]++@)~', $data)) { + return; + } + + $schemaSeparator = $this->hasAuthority($this->defaultProtocol) ? '://' : ':'; + if (!preg_match('~^(?:[/.]|[\w+.-]+' . $schemaSeparator . '|[^:/?@#]++@)~', $data)) { + $event->setData($this->defaultProtocol . $schemaSeparator . $data); + } + } + + private function hasAuthority($protocol) + { + return in_array($protocol, ['mailto', 'tel']) ? false : true; + } + + public static function getSubscribedEvents() + { + return [FormEvents::SUBMIT => 'onSubmit']; + } +} diff --git a/src/lib/Form/Type/FieldType/UrlFieldType.php b/src/lib/Form/Type/FieldType/UrlFieldType.php index 47fdf990..5e843a64 100644 --- a/src/lib/Form/Type/FieldType/UrlFieldType.php +++ b/src/lib/Form/Type/FieldType/UrlFieldType.php @@ -49,8 +49,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) [ 'label' => /** @Desc("URL") */ 'content.field_type.ezurl.link', 'required' => $options['required'], + 'default_protocol' => null, ] ) + ->addEventSubscriber(new FixUrlProtocolListener()) ->add( 'text', TextType::class, From 8322c56ad545b5b17b52e4a0c73e1380d378ffa2 Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Tue, 13 Jan 2026 11:43:17 +0100 Subject: [PATCH 02/10] code fix --- src/lib/Form/EventSubscriber/FixUrlProtocolListener.php | 7 ++++--- src/lib/Form/Type/FieldType/UrlFieldType.php | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php index 899f7673..f8ad48dc 100644 --- a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php +++ b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php @@ -14,6 +14,7 @@ class FixUrlProtocolListener implements EventSubscriberInterface { + /** @var string|null */ private $defaultProtocol; /** @@ -24,7 +25,7 @@ public function __construct(?string $defaultProtocol = 'http') $this->defaultProtocol = $defaultProtocol; } - public function onSubmit(FormEvent $event) + public function onSubmit(FormEvent $event): void { $data = $event->getData(); if (null === $this->defaultProtocol || empty($data) || !\is_string($data)) { @@ -46,12 +47,12 @@ public function onSubmit(FormEvent $event) } } - private function hasAuthority($protocol) + private function hasAuthority(string $protocol): bool { return in_array($protocol, ['mailto', 'tel']) ? false : true; } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [FormEvents::SUBMIT => 'onSubmit']; } diff --git a/src/lib/Form/Type/FieldType/UrlFieldType.php b/src/lib/Form/Type/FieldType/UrlFieldType.php index 5e843a64..c5250d52 100644 --- a/src/lib/Form/Type/FieldType/UrlFieldType.php +++ b/src/lib/Form/Type/FieldType/UrlFieldType.php @@ -9,6 +9,7 @@ namespace Ibexa\ContentForms\Form\Type\FieldType; use Ibexa\ContentForms\FieldType\DataTransformer\FieldValueTransformer; +use Ibexa\ContentForms\Form\EventSubscriber\FixUrlProtocolListener; use Ibexa\Contracts\Core\Repository\FieldTypeService; use JMS\TranslationBundle\Annotation\Desc; use Symfony\Component\Form\AbstractType; From bdeef523e6b91c587e2232b26bdda6faf1fbd025 Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Tue, 13 Jan 2026 17:13:41 +0100 Subject: [PATCH 03/10] Use Symfony FixUrlProtocolListener when possible --- .../FixUrlProtocolListener.php | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php index f8ad48dc..884b1df6 100644 --- a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php +++ b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php @@ -9,6 +9,7 @@ namespace Ibexa\ContentForms\Form\EventSubscriber; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener as BaseFixUrlProtocolListener; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; @@ -17,33 +18,43 @@ class FixUrlProtocolListener implements EventSubscriberInterface /** @var string|null */ private $defaultProtocol; + /** @var Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener */ + private $fixUrlProtocolListener; + /** * @param string|null $defaultProtocol The URL scheme to add when there is none or null to not modify the data */ public function __construct(?string $defaultProtocol = 'http') { $this->defaultProtocol = $defaultProtocol; + $this->fixUrlProtocolListener = new BaseFixUrlProtocolListener($defaultProtocol); } public function onSubmit(FormEvent $event): void { $data = $event->getData(); - if (null === $this->defaultProtocol || empty($data) || !\is_string($data)) { + $dataLink = $data['link'] ?? null; + if (is_null($this->defaultProtocol) || empty($data) || empty($dataLink) || !\is_string($dataLink)){ return; } - - $protocol = explode(':', $data)[0]; - if ($this->hasAuthority($protocol) && preg_match('~^(?:[/.]|[\w+.-]+://|[^:/?@#]++@)~', $data)) { + + $protocol = explode(':', $dataLink)[0]; + if ($this->hasAuthority($protocol) && $this->hasAuthority($this->defaultProtocol)) { + $event->setData($dataLink); + $this->fixUrlProtocolListener->onSubmit($event); + $data['link'] = $event->getData(); + $event->setData($data); return; } - if (!$this->hasAuthority($protocol) && preg_match('~^(?:[/.]|[\w+.-]+:|[^:/?@#]++@)~', $data)) { + if (!$this->hasAuthority($protocol) && preg_match('~^(?:[/.]|[\w+.-]+:|[^:/?@#]++@)~', $dataLink)) { return; } $schemaSeparator = $this->hasAuthority($this->defaultProtocol) ? '://' : ':'; - if (!preg_match('~^(?:[/.]|[\w+.-]+' . $schemaSeparator . '|[^:/?@#]++@)~', $data)) { - $event->setData($this->defaultProtocol . $schemaSeparator . $data); + if (!preg_match('~^(?:[/.]|[\w+.-]+'. $schemaSeparator. '|[^:/?@#]++@)~', $dataLink)) { + $data['link'] = $this->defaultProtocol. $schemaSeparator. $dataLink; + $event->setData($data); } } From 6ce6946f1ab6e788f89e0fb7d7e2fea388d9fcba Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Tue, 13 Jan 2026 17:14:25 +0100 Subject: [PATCH 04/10] Added test for FixUrlProtocolListener --- .../FixUrlProtocolListenerTest.php | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php diff --git a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php new file mode 100644 index 00000000..ddb0d796 --- /dev/null +++ b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php @@ -0,0 +1,97 @@ +|null $inputData + * @param array|null $expectedData + * @param string $defaultProtocol + */ + public function testUrlProtocolHandling(?array $inputData, ?array $expectedData, ?string $defaultProtocol = 'http'): void + { + $form = $this->createMock(FormInterface::class); + $listener = new FixUrlProtocolListener($defaultProtocol); + + $event = new FormEvent($form, $inputData); + + $listener->onSubmit($event); + + self::assertSame($expectedData, $event->getData()); + } + + /** + * @return iterable|null, + * 1: array|null + * }> + */ + public static function provideUrlCases(): iterable + { + yield 'adds http when protocol missing' => [ + ['link' => 'example.com'], + ['link' => 'http://example.com'], + ]; + + yield 'does not modify https url' => [ + ['link' => 'https://example.com'], + ['link' => 'https://example.com'], + ]; + + yield 'does not modify http url' => [ + ['link' => 'http://example.com'], + ['link' => 'http://example.com'], + ]; + + yield 'keeps ftp intact' => [ + ['link' => 'ftp://example.com'], + ['link' => 'ftp://example.com'], + ]; + + yield 'keeps tel intact' => [ + ['link' => 'tel:+123456'], + ['link' => 'tel:+123456'], + ]; + + yield 'adds default tel' => [ + ['link' => '+123456'], + ['link' => 'tel:+123456'], + 'tel', + ]; + + yield 'adds default mailto' => [ + ['link' => 'me@home.de'], + ['link' => 'mailto:me@home.de'], + 'mailto', + ]; + + yield 'does nothing when link is empty string' => [ + ['link' => ''], + ['link' => ''], + ]; + + yield 'does nothing when link key is missing' => [ + [], + [], + ]; + + yield 'does nothing when data is null' => [ + null, + null, + ]; + } +} From 096ba1dc88982214d497bde48d6add6bfc1fc551 Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Tue, 13 Jan 2026 17:20:41 +0100 Subject: [PATCH 05/10] Code Fix --- .../Form/EventSubscriber/FixUrlProtocolListener.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php index 884b1df6..1c738adc 100644 --- a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php +++ b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php @@ -18,7 +18,7 @@ class FixUrlProtocolListener implements EventSubscriberInterface /** @var string|null */ private $defaultProtocol; - /** @var Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener */ + /** @var \Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener */ private $fixUrlProtocolListener; /** @@ -34,16 +34,17 @@ public function onSubmit(FormEvent $event): void { $data = $event->getData(); $dataLink = $data['link'] ?? null; - if (is_null($this->defaultProtocol) || empty($data) || empty($dataLink) || !\is_string($dataLink)){ + if (null === $this->defaultProtocol || empty($data) || empty($dataLink) || !\is_string($dataLink)) { return; } - + $protocol = explode(':', $dataLink)[0]; if ($this->hasAuthority($protocol) && $this->hasAuthority($this->defaultProtocol)) { $event->setData($dataLink); $this->fixUrlProtocolListener->onSubmit($event); $data['link'] = $event->getData(); $event->setData($data); + return; } @@ -52,8 +53,8 @@ public function onSubmit(FormEvent $event): void } $schemaSeparator = $this->hasAuthority($this->defaultProtocol) ? '://' : ':'; - if (!preg_match('~^(?:[/.]|[\w+.-]+'. $schemaSeparator. '|[^:/?@#]++@)~', $dataLink)) { - $data['link'] = $this->defaultProtocol. $schemaSeparator. $dataLink; + if (!preg_match('~^(?:[/.]|[\w+.-]+' . $schemaSeparator . '|[^:/?@#]++@)~', $dataLink)) { + $data['link'] = $this->defaultProtocol . $schemaSeparator . $dataLink; $event->setData($data); } } From ebc75bd8cf66cfb98f4e3ec3ea1e358fa16ca861 Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Tue, 13 Jan 2026 18:23:45 +0100 Subject: [PATCH 06/10] Fix mailto handling --- .../EventSubscriber/FixUrlProtocolListener.php | 11 +++++++++-- .../EventSubscriber/FixUrlProtocolListenerTest.php | 14 ++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php index 1c738adc..30c91085 100644 --- a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php +++ b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php @@ -52,8 +52,15 @@ public function onSubmit(FormEvent $event): void return; } - $schemaSeparator = $this->hasAuthority($this->defaultProtocol) ? '://' : ':'; - if (!preg_match('~^(?:[/.]|[\w+.-]+' . $schemaSeparator . '|[^:/?@#]++@)~', $dataLink)) { + if ($this->hasAuthority($this->defaultProtocol)) { + $schemaSeparator = '://'; + $regExp = '~^(?:[/.]|[\w+.-]+//|[^:/?@#]++@)~'; + } else { + $schemaSeparator = ':'; + $regExp = '~^[\w+.-]+:~'; // allowing emails for non-http/https/file + } + + if (!preg_match($regExp, $dataLink)) { $data['link'] = $this->defaultProtocol . $schemaSeparator . $dataLink; $event->setData($data); } diff --git a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php index ddb0d796..e4b95217 100644 --- a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php +++ b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php @@ -57,6 +57,11 @@ public static function provideUrlCases(): iterable ['link' => 'http://example.com'], ]; + yield 'keep relative url with leading / intact' => [ + ['link' => '/foo/bar'], + ['link' => '/foo/bar'], + ]; + yield 'keeps ftp intact' => [ ['link' => 'ftp://example.com'], ['link' => 'ftp://example.com'], @@ -73,9 +78,14 @@ public static function provideUrlCases(): iterable 'tel', ]; + yield 'keeps mailto intact' => [ + ['link' => 'mailto:me@home.com'], + ['link' => 'mailto:me@home.com'], + ]; + yield 'adds default mailto' => [ - ['link' => 'me@home.de'], - ['link' => 'mailto:me@home.de'], + ['link' => 'me@home'], + ['link' => 'mailto:me@home'], 'mailto', ]; From b9c871896dbdfbee5b32d7bc199dda87fb2d1893 Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Tue, 13 Jan 2026 18:29:11 +0100 Subject: [PATCH 07/10] Fix mailto handling --- .../FixUrlProtocolListenerTest.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php index e4b95217..ed5ef8ce 100644 --- a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php +++ b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php @@ -43,18 +43,18 @@ public function testUrlProtocolHandling(?array $inputData, ?array $expectedData, public static function provideUrlCases(): iterable { yield 'adds http when protocol missing' => [ - ['link' => 'example.com'], - ['link' => 'http://example.com'], + ['link' => 'example1.com'], + ['link' => 'http://example1.com'], ]; yield 'does not modify https url' => [ - ['link' => 'https://example.com'], - ['link' => 'https://example.com'], + ['link' => 'https://example2.com'], + ['link' => 'https://example2.com'], ]; yield 'does not modify http url' => [ - ['link' => 'http://example.com'], - ['link' => 'http://example.com'], + ['link' => 'http://example3.com'], + ['link' => 'http://example3.com'], ]; yield 'keep relative url with leading / intact' => [ @@ -63,8 +63,8 @@ public static function provideUrlCases(): iterable ]; yield 'keeps ftp intact' => [ - ['link' => 'ftp://example.com'], - ['link' => 'ftp://example.com'], + ['link' => 'ftp://example4.com'], + ['link' => 'ftp://example4.com'], ]; yield 'keeps tel intact' => [ @@ -79,13 +79,13 @@ public static function provideUrlCases(): iterable ]; yield 'keeps mailto intact' => [ - ['link' => 'mailto:me@home.com'], - ['link' => 'mailto:me@home.com'], + ['link' => 'mailto:foo@home.com'], + ['link' => 'mailto:foo@home.com'], ]; yield 'adds default mailto' => [ - ['link' => 'me@home'], - ['link' => 'mailto:me@home'], + ['link' => 'bar@home'], + ['link' => 'mailto:bar@home'], 'mailto', ]; From 32d43b3488361ba161328ab6f87863f3ac230542 Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Tue, 13 Jan 2026 20:11:05 +0100 Subject: [PATCH 08/10] Improved SonarQube result --- .../FixUrlProtocolListenerTest.php | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php index ed5ef8ce..d5eb6e2c 100644 --- a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php +++ b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php @@ -15,6 +15,16 @@ final class FixUrlProtocolListenerTest extends TestCase { + private const DOMAIN = 'example.com'; + private const MAIL = 'foo@' . self::DOMAIN; + private const TEL = '+123456'; + private const URL_HTTP = 'http://' . self::DOMAIN; + private const URL_HTTPS = 'https://' . self::DOMAIN; + private const URL_MAILTO = 'mailto:' . self::MAIL; + private const URL_RELATIVE = '/foo/bar/'; + private const URL_SFTP = 'sftp://' . self::DOMAIN; + private const URL_TEL = 'tel:' . self::TEL; + /** * @dataProvider provideUrlCases * @@ -43,49 +53,49 @@ public function testUrlProtocolHandling(?array $inputData, ?array $expectedData, public static function provideUrlCases(): iterable { yield 'adds http when protocol missing' => [ - ['link' => 'example1.com'], - ['link' => 'http://example1.com'], + ['link' => self::DOMAIN], + ['link' => self::URL_HTTP], ]; yield 'does not modify https url' => [ - ['link' => 'https://example2.com'], - ['link' => 'https://example2.com'], + ['link' => self::URL_HTTPS], + ['link' => self::URL_HTTPS], ]; yield 'does not modify http url' => [ - ['link' => 'http://example3.com'], - ['link' => 'http://example3.com'], + ['link' => self::URL_HTTP], + ['link' => self::URL_HTTP], ]; yield 'keep relative url with leading / intact' => [ - ['link' => '/foo/bar'], - ['link' => '/foo/bar'], + ['link' => self::URL_RELATIVE], + ['link' => self::URL_RELATIVE], ]; yield 'keeps ftp intact' => [ - ['link' => 'ftp://example4.com'], - ['link' => 'ftp://example4.com'], + ['link' => self::URL_SFTP], + ['link' => self::URL_SFTP], ]; yield 'keeps tel intact' => [ - ['link' => 'tel:+123456'], - ['link' => 'tel:+123456'], + ['link' => self::URL_TEL], + ['link' => self::URL_TEL], ]; yield 'adds default tel' => [ - ['link' => '+123456'], - ['link' => 'tel:+123456'], + ['link' => self::TEL], + ['link' => self::URL_TEL], 'tel', ]; yield 'keeps mailto intact' => [ - ['link' => 'mailto:foo@home.com'], - ['link' => 'mailto:foo@home.com'], + ['link' => self::URL_MAILTO], + ['link' => self::URL_MAILTO], ]; yield 'adds default mailto' => [ - ['link' => 'bar@home'], - ['link' => 'mailto:bar@home'], + ['link' => self::MAIL], + ['link' => self::URL_MAILTO], 'mailto', ]; From 12c80177053a2c570fca0858bd877bc66fea03ee Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Tue, 13 Jan 2026 20:52:32 +0100 Subject: [PATCH 09/10] Minor fix --- .../FixUrlProtocolListener.php | 2 +- .../FixUrlProtocolListenerTest.php | 111 ++++++++---------- 2 files changed, 52 insertions(+), 61 deletions(-) diff --git a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php index 30c91085..62204ec2 100644 --- a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php +++ b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php @@ -68,7 +68,7 @@ public function onSubmit(FormEvent $event): void private function hasAuthority(string $protocol): bool { - return in_array($protocol, ['mailto', 'tel']) ? false : true; + return !in_array($protocol, ['mailto', 'tel']); } public static function getSubscribedEvents(): array diff --git a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php index d5eb6e2c..ad9b2945 100644 --- a/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php +++ b/tests/lib/Form/EventSubscriber/FixUrlProtocolListenerTest.php @@ -52,66 +52,57 @@ public function testUrlProtocolHandling(?array $inputData, ?array $expectedData, */ public static function provideUrlCases(): iterable { - yield 'adds http when protocol missing' => [ - ['link' => self::DOMAIN], - ['link' => self::URL_HTTP], - ]; - - yield 'does not modify https url' => [ - ['link' => self::URL_HTTPS], - ['link' => self::URL_HTTPS], - ]; - - yield 'does not modify http url' => [ - ['link' => self::URL_HTTP], - ['link' => self::URL_HTTP], - ]; - - yield 'keep relative url with leading / intact' => [ - ['link' => self::URL_RELATIVE], - ['link' => self::URL_RELATIVE], - ]; - - yield 'keeps ftp intact' => [ - ['link' => self::URL_SFTP], - ['link' => self::URL_SFTP], - ]; - - yield 'keeps tel intact' => [ - ['link' => self::URL_TEL], - ['link' => self::URL_TEL], - ]; - - yield 'adds default tel' => [ - ['link' => self::TEL], - ['link' => self::URL_TEL], - 'tel', - ]; - - yield 'keeps mailto intact' => [ - ['link' => self::URL_MAILTO], - ['link' => self::URL_MAILTO], - ]; - - yield 'adds default mailto' => [ - ['link' => self::MAIL], - ['link' => self::URL_MAILTO], - 'mailto', - ]; - - yield 'does nothing when link is empty string' => [ - ['link' => ''], - ['link' => ''], - ]; - - yield 'does nothing when link key is missing' => [ - [], - [], - ]; - - yield 'does nothing when data is null' => [ - null, - null, + return [ + 'adds http when protocol missing' => [ + ['link' => self::DOMAIN], + ['link' => self::URL_HTTP], + ], + 'does not modify https url' => [ + ['link' => self::URL_HTTPS], + ['link' => self::URL_HTTPS], + ], + 'does not modify http url' => [ + ['link' => self::URL_HTTP], + ['link' => self::URL_HTTP], + ], + 'keep relative url with leading / intact' => [ + ['link' => self::URL_RELATIVE], + ['link' => self::URL_RELATIVE], + ], + 'keeps ftp intact' => [ + ['link' => self::URL_SFTP], + ['link' => self::URL_SFTP], + ], + 'keeps tel intact' => [ + ['link' => self::URL_TEL], + ['link' => self::URL_TEL], + ], + 'adds default tel' => [ + ['link' => self::TEL], + ['link' => self::URL_TEL], + 'tel', + ], + 'keeps mailto intact' => [ + ['link' => self::URL_MAILTO], + ['link' => self::URL_MAILTO], + ], + 'adds default mailto' => [ + ['link' => self::MAIL], + ['link' => self::URL_MAILTO], + 'mailto', + ], + 'does nothing when link is empty string' => [ + ['link' => ''], + ['link' => ''], + ], + 'does nothing when link key is missing' => [ + [], + [], + ], + 'does nothing when data is null' => [ + null, + null, + ], ]; } } From 1080bbe68113ea36d3e49774f0826ada9d200393 Mon Sep 17 00:00:00 2001 From: Thorsten Reiter Date: Thu, 29 Jan 2026 16:58:56 +0100 Subject: [PATCH 10/10] Changes from code review --- src/lib/Form/EventSubscriber/FixUrlProtocolListener.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php index 62204ec2..602add4c 100644 --- a/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php +++ b/src/lib/Form/EventSubscriber/FixUrlProtocolListener.php @@ -13,7 +13,10 @@ use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; -class FixUrlProtocolListener implements EventSubscriberInterface +/** + * @internal + */ +final class FixUrlProtocolListener implements EventSubscriberInterface { /** @var string|null */ private $defaultProtocol; @@ -68,7 +71,7 @@ public function onSubmit(FormEvent $event): void private function hasAuthority(string $protocol): bool { - return !in_array($protocol, ['mailto', 'tel']); + return !in_array($protocol, ['mailto', 'tel'], true); } public static function getSubscribedEvents(): array