Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel] [WebProfileBundle] Fix Routing panel for URLs with a colon #57917

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

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

akeylimepie
Copy link
Contributor

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Issues see below
License MIT

According to docs the parse_url function may not produce the expected result for relative URLs. In particular, the function produces incorrect results for a relative URL with a port-like string in any part, such as:

parse_url('/foo/bar:123/baz'); // false

But such a URL is valid. So if there is a controller with this route for it, Symfony will correctly match it:

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

class HelloController extends AbstractController
{
    #[Route('/foo/bar:123/baz')]
    public function world()
    {
        return new Response();
    }
}
match

Bug

But in the profiler, opening the Routing panel will not work; instead of the panel, we see an exception:

fail

This is because Symfony\Bundle\WebProfilerBundle\Controller::getTraces method creates a new Request from relative path info. And Request::create since 6.3 #49376 throws an exception if parse_url returns false, which is the case here:

Prior to version 6.3, the routing panel is displayed, but there are no router matches on it. This is why version 5.4 is also affected.


Solution

So instead of a relative path, I suggest using an absolute URI, which is handled by parse_url correctly:

success

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.2 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title [WebProfileBundle][HttpKernel] Fix Routing panel for URLs with a colon [HttpKernel] [WebProfileBundle] Fix Routing panel for URLs with a colon Aug 3, 2024
@akeylimepie
Copy link
Contributor Author

akeylimepie commented Aug 4, 2024

I took another look. Instead of reparsing the relative path info, we can simply call the Request constructor, as all the necessary data is already available. So, there are no breaking changes.

@akeylimepie akeylimepie changed the title [HttpKernel] [WebProfileBundle] Fix Routing panel for URLs with a colon [WebProfileBundle] Fix Routing panel for URLs with a colon Aug 4, 2024
Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change itself looks good to me. But I have some remarks for the test.

@akeylimepie akeylimepie force-pushed the fix-router-panel branch 2 times, most recently from dcc006a to 392570e Compare August 6, 2024 14:38
@OskarStark
Copy link
Contributor

cc @alexandre-daubois as you worked on the URI component

@carsonbot carsonbot changed the title [WebProfileBundle] Fix Routing panel for URLs with a colon [HttpKernel] [WebProfileBundle] Fix Routing panel for URLs with a colon Aug 8, 2024
@nicolas-grekas
Copy link
Member

Thank you @akeylimepie.

@nicolas-grekas nicolas-grekas merged commit 1a7fa93 into symfony:5.4 Aug 8, 2024
2 checks passed
@dpakyy
Copy link

dpakyy commented Aug 8, 2024

Oh my god, this is amazing, thank you!

@akeylimepie akeylimepie deleted the fix-router-panel branch August 8, 2024 17:46
This was referenced Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants