Просмотр исходного кода

Preserve remainder of path in URI after database (redis scheme).

Daniele Alessandri 9 лет назад
Родитель
Сommit
1f7b534072
2 измененных файлов с 26 добавлено и 2 удалено
  1. 7 2
      src/Connection/Parameters.php
  2. 19 0
      tests/Predis/Connection/ParametersTest.php

+ 7 - 2
src/Connection/Parameters.php

@@ -114,9 +114,14 @@ class Parameters implements ParametersInterface
                 unset($parsed['pass']);
             }
 
-            if (isset($parsed['path']) && preg_match('/^\/(\d+)\/?/', $parsed['path'], $path)) {
+            if (isset($parsed['path']) && preg_match('/^\/(\d+)(\/.*)?/', $parsed['path'], $path)) {
                 $parsed['database'] = $path[1];
-                unset($parsed['path']);
+
+                if (isset($path[2])) {
+                    $parsed['path'] = $path[2];
+                } else {
+                    unset($parsed['path']);
+                }
             }
         }
 

+ 19 - 0
tests/Predis/Connection/ParametersTest.php

@@ -179,6 +179,25 @@ class ParametersTest extends PredisTestCase
         $this->assertSame($expected, $parameters);
     }
 
+    /**
+     * @group disconnected
+     */
+    public function testParsingURIWithRedisSchemeMustPreserveRemainderOfPath()
+    {
+        $uri = 'redis://10.10.10.10/5/rest/of/path';
+
+        $expected = array(
+            'scheme' => 'redis',
+            'host' => '10.10.10.10',
+            'path' => '/rest/of/path',
+            'database' => '5',
+        );
+
+        $parameters = Parameters::parse($uri);
+
+        $this->assertSame($expected, $parameters);
+    }
+
     /**
      * @group disconnected
      */