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

Skip to content

[Routing] URL doesn't match correct route due to escaped characters #752

Closed
@ghost

Description

Commas (",") and pluses ("+") are legal characters in path segment of the URL so I think Symfony\Component\Routing\Generator\UrlGenerator should not escape them.

Currently due to escaping:

  • correct route doesn't match when the "requirements" regex contains these characters (it's a bug)
  • bad looking url shows up in the user browser address bar
  • this can lead to duplicate content issues with search engines

Example use case:

route:

category_with_params:
    pattern:        /{category}/{params}/
    defaults:       { _controller: CompanyProjectBundle:Category:show }
    requirements:   { params: "[0-9a-z-]+(,[0-9a-z-]+)+(/[0-9a-z-]+(,[0-9a-z-]+)+)*" }

passed values:

category = laptops
params = brand,acer

expected path:

 /laptops/brand,acer/

generated path:

 /laptops/brand%2Cacer/

following generated path doesn't match "category_with_params" route and produces error (if no other matching routes exists):

No route found for "GET /laptops/brand%2Cacer/" 

Possible fix:

Replace 115 line in Symfony\Component\Routing\Generator\UrlGenerator:

                    $url = $token[1].str_replace('%2F', '/', urlencode($tparams[$token[3]])).$url;

with

                    $url = $token[1].str_replace(
                        array('%2F', '%2B', '%2C'),
                        array('/',   '+',   ','),
                        urlencode($tparams[$token[3]])
                    ).$url;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions