浏览代码

[Routing] Route collection prefixes must start with a / and must not end with a /

Fabien Potencier 14 年之前
父节点
当前提交
98e70f0963
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      src/Symfony/Component/Routing/RouteCollection.php

+ 8 - 0
src/Symfony/Component/Routing/RouteCollection.php

@@ -120,10 +120,18 @@ class RouteCollection implements \IteratorAggregate
      */
     public function addPrefix($prefix)
     {
+        // a prefix must not end with a slash
+        $prefix = rtrim($prefix, '/');
+
         if (!$prefix) {
             return;
         }
 
+        // a prefix must start with a slash
+        if ('/' !== $prefix[0]) {
+            $prefix = '/'.$prefix;
+        }
+
         $this->prefix = $prefix.$this->prefix;
 
         foreach ($this->all() as $route) {