Browse Source

Avoid double slash

Rachman Chavik 8 years ago
parent
commit
16228203c1
2 changed files with 5 additions and 1 deletions
  1. 1 1
      src/Routing/RouteBuilder.php
  2. 4 0
      tests/TestCase/Routing/RouteBuilderTest.php

+ 1 - 1
src/Routing/RouteBuilder.php

@@ -613,7 +613,7 @@ class RouteBuilder
         }
         $name = Inflector::underscore($name);
         if (isset($params['path'])) {
-            $path = '/' . $params['path'];
+            $path = ($params['path'][0] === '/' ? '' : '/') . $params['path'];
             unset($params['path']);
         } else {
             $path = '/' . $name;

+ 4 - 0
tests/TestCase/Routing/RouteBuilderTest.php

@@ -362,6 +362,10 @@ class RouteBuilderTest extends TestCase
             $r->prefix('v10', ['path' => 'v1.0'], function ($r2) {
                 $this->assertEquals('/admin/api/v1.0', $r2->path());
                 $this->assertEquals(['prefix' => 'admin/api/v10'], $r2->params());
+                $r2->prefix('b1', ['path' => '/beta.1'], function ($r3) {
+                    $this->assertEquals('/admin/api/v1.0/beta.1', $r3->path());
+                    $this->assertEquals(['prefix' => 'admin/api/v10/b1'], $r3->params());
+                });
             });
         });
         $this->assertNull($res);