8000 [Form] Skipped URL protocol "//~" is normal but not valid by FixUrlProtocolListener · Issue #42329 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexanevsky opened this issue Jul 30, 2021 · 1 comment

Comments

@alexanevsky
Copy link
alexanevsky commented Jul 30, 2021

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, '//')) {
@alexanevsky alexanevsky changed the title [Form] Skipped protocol "//~" is normal but not valid by FixUrlProtocolListener [Form] Skipped URL protocol "//~" is normal but not valid by FixUrlProtocolListener Jul 30, 2021
@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

nicolas-grekas added a commit that referenced this issue Jan 31, 2022
…antin)

This PR was merged into the 4.4 branch.

Discussion
----------

[Form] Do not fix URL protocol for relative URLs

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Tickets | Fix #42329
| Deprecations? | no
| License       | MIT

Example when it doesn't work correctly:
/relative/path
The data will be changed to "http:///relative/path" (3 slashes)

Commits
-------

415dc19 [Form] Do not fix URL protocol for relative URLs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0