Skip to content

[Form] Skipped URL protocol "//~" is normal but not valid by FixUrlProtocolListener #42329

Closed
@alexanevsky

Description

@alexanevsky

Symfony version(s) affected: <=5.3

Description

It is normal to use links without absolute protocol, just: //symfony.com

After following a link without a protocol (only with double slashes), browsers will automatically detect the protocol. So it is correct to use these links. Try and see: //symfony.com

But Symfony Form UrlType adds a default protocol to these URLs (//symfony.com => http:////symfony.com).

How to reproduce
Paste //symfony.com to Form UrlType, submit the form and see what happens.

Possible Solution
In Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener
Find:

if ($this->defaultProtocol && $data && \is_string($data) && !preg_match('~^[\w+.-]+://~', $data)) {

Replace to:

if ($this->defaultProtocol && $data && \is_string($data) && !preg_match('~^[\w+.-]+://~', $data) && 0 !== strpos($data, '//')) {

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions