Clone Horde_Url objects in static methods.
authorChuck Hagenbuch <chuck@horde.org>
Sat, 5 Dec 2009 04:51:58 +0000 (23:51 -0500)
committerChuck Hagenbuch <chuck@horde.org>
Sat, 5 Dec 2009 04:51:58 +0000 (23:51 -0500)
This avoids reference problems changing URLs as a result of later calls when
we're building pieces of URLs repeatedly. This can lead to really bad behavior,
like deletion of tasks in Nag when clicking what's supposed to be an edit link.

framework/Util/lib/Horde/Util.php

index 29e0d95..6eaa734 100644 (file)
@@ -235,8 +235,13 @@ class Horde_Util
         }
 
         if ($url instanceof Horde_Url) {
-            $url->raw = !$encode;
-            return $url->add($parameter, $value);
+            // In many places we re-use URLs assuming they are strings. With
+            // Horde_Url objects, this can lead to reference problems and URLs
+            // being mysteriously modified. For now, we have to clone any
+            // objects to avoid modifying them.
+            $url2 = clone($url);
+            $url2->raw = !$encode;
+            return $url2->add($parameter, $value);
         }
 
         $horde_url = new Horde_Url($url, !$encode);
@@ -254,12 +259,16 @@ class Horde_Util
      */
     static public function removeParameter($url, $remove)
     {
-        $horde_url = new Horde_Url($url);
-
         if ($url instanceof Horde_Url) {
-            return $url->remove($remove);
+            // In many places we re-use URLs assuming they are strings. With
+            // Horde_Url objects, this can lead to reference problems and URLs
+            // being mysteriously modified. For now, we have to clone any
+            // objects to avoid modifying them.
+            $url2 = clone($url);
+            return $url2->remove($remove);
         }
 
+        $horde_url = new Horde_Url($url);
         return $horde_url->remove($remove);
     }