From 005d2b7805829948cd0ea6d016421480db1a00b4 Mon Sep 17 00:00:00 2001 From: yangyang Date: Tue, 30 Apr 2019 22:00:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E5=90=8D=E6=88=96=E5=AF=86=E7=A0=81=E4=B8=AD=E5=B8=A6=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E5=AD=97=E7=AC=A6@:=E6=97=B6=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5MongoDB=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Connection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 5df5d16..6a6c484 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -186,7 +186,7 @@ public function connect(array $config = [], $linkNum = 0) } if (empty($config['dsn'])) { - $config['dsn'] = 'mongodb://' . ($config['username'] ? "{$config['username']}" : '') . ($config['password'] ? ":{$config['password']}@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : ''); + $config['dsn'] = 'mongodb://' . ($config['username'] ? str_replace(['@', ':'], ['%40', '%3A'], $config['username']) : '') . ($config['password'] ? ":" . str_replace(['@', ':'], ['%40', '%3A'], $config['password']) . "@" : '') . $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : ''); } if ($config['debug']) { @@ -696,7 +696,7 @@ public function replicaSetConnect() */ private function buildUrl() { - $url = 'mongodb://' . ($this->config['username'] ? "{$this->config['username']}" : '') . ($this->config['password'] ? ":{$this->config['password']}@" : ''); + $url = 'mongodb://' . ($this->config['username'] ? str_replace(['@', ':'], ['%40', '%3A'], $this->config['username']) : '') . ($this->config['password'] ? ":" . str_replace(['@', ':'], ['%40', '%3A'], $this->config['password']) . "@" : ''); $hostList = explode(',', $this->config['hostname']); $portList = explode(',', $this->config['hostport']);