Development

#5001 (sfRoute::generate() doesn't handle params with NULL default value correctly)

You must first sign up to be able to contribute.

Ticket #5001 (closed defect: fixed)

Opened 8 months ago

Last modified 7 months ago

sfRoute::generate() doesn't handle params with NULL default value correctly

Reported by: rs Assigned to: fabien
Priority: minor Milestone: 1.2.0 RC2
Component: routing Version: 1.2.0 BETA2
Keywords: Cc:
Qualification: Unreviewed

Description

SF's routing accept NULL as default value for parameters but can't handle generation correctly. In the following example, the route will match, but generation will fail, telling a mandatory parameter is missing:

myroute:
  url: /foo/:bar
  param: { bar: ~ }

This is because an array_filter() is performed on parameters before to check if all mandatory parameters are present. The fix would be to remove this array_filter() (see patch below).

diff --git a/lib/routing/sfRoute.class.php b/lib/routing/sfRoute.class.php
index c24c72d..3bc02e2 100644
--- a/lib/routing/sfRoute.class.php
+++ b/lib/routing/sfRoute.class.php
@@ -206,7 +206,7 @@ class sfRoute implements Serializable
     $tparams = $this->mergeArrays($defaults, $params);
 
     // all params must be given
-    if ($diff = array_diff_key($this->variables, array_filter($tparams)))
+    if ($diff = array_diff_key($this->variables, $tparams))
     {
       throw new InvalidArgumentException(sprintf('The "%s" route has some missing mandatory parameters (%s).', $this->pattern, implode(', ', $diff)));
     }

Change History

11/20/08 02:07:14 changed by rs

I think this ticket duplicates: #4960

11/23/08 11:15:08 changed by FabianLange

  • milestone changed from 1.2.0 to 1.2.0 RC2.

11/24/08 23:22:22 changed by fabien

  • status changed from new to closed.
  • resolution set to fixed.

in r13322

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.