浏览代码

Better checks for arguments passed to Predis\ConnectionParameters.

Daniele Alessandri 14 年之前
父节点
当前提交
a992d9d0b8
共有 1 个文件被更改,包括 7 次插入3 次删除
  1. 7 3
      lib/Predis.php

+ 7 - 3
lib/Predis.php

@@ -905,12 +905,15 @@ class ConnectionParameters {
     }
 
     protected function parseURI($uri) {
+        if (!is_string($uri)) {
+            throw new \InvalidArgumentException('URI must be a string');
+        }
         if (stripos($uri, 'unix') === 0) {
             // Hack to support URIs for UNIX sockets with minimal effort
             $uri = str_ireplace('unix:///', 'unix://localhost/', $uri);
         }
         $parsed = @parse_url($uri);
-        if ($parsed == false || $parsed['host'] == null) {
+        if ($parsed == false || !isset($parsed['host'])) {
             throw new ClientException("Invalid URI: $uri");
         }
         if (array_key_exists('query', $parsed)) {
@@ -1262,8 +1265,9 @@ class TcpConnection extends ConnectionBase implements IConnectionSingle {
     }
 
     protected function checkParameters(ConnectionParameters $parameters) {
-        if ($parameters->scheme != 'tcp' && $parameters->scheme != 'redis') {
-            throw new \InvalidArgumentException("Invalid scheme: {$parameters->scheme}");
+        $scheme = $parameters->scheme;
+        if ($scheme != 'tcp' && $scheme != 'redis') {
+            throw new \InvalidArgumentException("Invalid scheme: {$scheme}");
         }
         return $parameters;
     }