Development

#1824 (Incorrect handling of empty parameters in routing)

You must first sign up to be able to contribute.

Ticket #1824 (new defect)

Opened 1 year ago

Last modified 4 months ago

Incorrect handling of empty parameters in routing

Reported by: Ari.Pringle Assigned to: fabien
Priority: major Milestone:
Component: routing Version: 1.0.0
Keywords: Cc:
Qualification: Design decision

Description

URL generation (with url_for, genUrl, link_to, etc) creates an invalid URL in certain circumstances. Take the following example:

url_for('module/action?param1=&param2=val2')

Returns: http://my.domain.com/module/action/param1//param2/val2

.. which does not get properly parsed. It seems to me that it would be best to either have symfony parse "//" as an empty value (if possible), or have the URL generation not include empty parameters (thus creating /module/action/param2/val2 from the above example, completely removing the param1 parameter).

Also, if a trailing ampersand is included at the end of the string to be URL generated, such as:

url_for('module/action?param1=val1&')

Returns: http://my.domain.com/module/action/param1/val1%26

.. which appears to get parsed differently depending on if the no_script_name configuration variable is set in settings.yml (effectively making production & development environments act different). With no_script_name set to "off", it seems that getRequestParameter('param1') returns "val1". With no_script_name set to "on", it returns "val1&".

In my situation, having the URL generation discard trailing question marks, ampersands, and slashes, would be ideal.

On a somewhat related note, it would also be nice if trailing slashes in a URL didn't interfere with pulling up a page. Example:

This works fine: http://my.domain.com/module

This returns the "oops!" 404 error: http://my.domain.com/module/

Change History

06/20/07 11:15:54 changed by Eric.Lemoine

  • priority changed from minor to major.

I think the first problem (empty parameters not being parsed) is a big issue because it makes the url generation much more complicated. Indeed we have to test the length of the parameter value before adding it to the url. If it is empty the url generation works (/parameter_name//) but the parsing do not work properly. The most simple modification, as suggested by Ari.Pringle, should be to skip the empty parameters in the url generation.

Hope this will be corrected in the next stable release ;)

07/14/07 01:18:10 changed by Ari.Pringle

I would like to slightly alter my original request.

After a little thought on the matter, I can see uses for having empty parameters (and possibly tailing ampersands, equals, etc).

For example, I have recently used url_for to build the http://server/module/action/param1/ part of a URL, then used javascript to populate the value. So for this, it seems that leaving the URL generation the same, but allowing symfony to parse empty values properly, would be ideal. A possible alternative would be a parameter that you could pass to url_for (and similar functions) that specifies whether or not to discard empty parameters.

However, the part about prod and dev environments parsing trailing ampersands differently (at least as of 1.0.5) is still a problem in my eyes. To reiterate:

http://server/module/action/param1/val1%26 # generated by url_for('module/action/param1/val1&')

The value of the param1 parameter comes out as val1 in the dev environment, and val1& in the prod environment.

04/22/08 10:01:45 changed by FabianLange

  • component changed from helpers to routing.
  • qualification set to Unreviewed.

#1934 and #2482 are duplicates of this. I closed #1934 because its really the same. #2482 is slightly different and also tagged for 1.1.

Changed to Routing, because the helper is doing ok. But the routing has parsing issues (see #2482, where this is described more in detail)

04/22/08 10:03:17 changed by FabianLange

  • qualification changed from Unreviewed to Design decision.

I would like to emphasize the importance of this bug. When having a look for duplicates I found that actually many people have an issue with this.

04/22/08 10:15:37 changed by FabianLange

  • summary changed from URL generation creates invalid URLs when passed empty or undefined parameters to Incorrect handling of empty parameters in routing.