From 9c6e35633f2ee1d47c12d760979269ac2d7b9db5 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Wed, 18 Sep 2019 13:21:26 +0300 Subject: [PATCH] Fix prependMissingScheme with underscore --- src/Elasticsearch/ClientBuilder.php | 2 +- tests/Elasticsearch/Tests/ClientTest.php | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Elasticsearch/ClientBuilder.php b/src/Elasticsearch/ClientBuilder.php index 15be6fd18..0ccbb1ddf 100644 --- a/src/Elasticsearch/ClientBuilder.php +++ b/src/Elasticsearch/ClientBuilder.php @@ -686,7 +686,7 @@ private function extractURIParts(string $host): array private function prependMissingScheme(string $host): string { - if (!filter_var($host, FILTER_VALIDATE_URL)) { + if (!preg_match("/^https?:\/\//", $host)) { $host = 'http://' . $host; } diff --git a/tests/Elasticsearch/Tests/ClientTest.php b/tests/Elasticsearch/Tests/ClientTest.php index 9a28c7e86..2ed42c120 100644 --- a/tests/Elasticsearch/Tests/ClientTest.php +++ b/tests/Elasticsearch/Tests/ClientTest.php @@ -312,6 +312,17 @@ public function testInlineHosts() $this->assertSame(9200, $host->getPort()); $this->assertSame("https", $host->getTransportSchema()); $this->assertSame("user:pass", $host->getUserPass()); + + $client = Elasticsearch\ClientBuilder::create()->setHosts( + [ + 'https://user:pass@the_foo.com:9200' + ] + )->build(); + $host = $client->transport->getConnection(); + $this->assertSame("the_foo.com", $host->getHost()); + $this->assertSame(9200, $host->getPort()); + $this->assertSame("https", $host->getTransportSchema()); + $this->assertSame("user:pass", $host->getUserPass()); } public function testExtendedHosts() @@ -417,7 +428,7 @@ public function testExtendedHosts() // good } - // Underscore host, questionably legal, but inline method would break + // Underscore host, questionably legal $client = Elasticsearch\ClientBuilder::create()->setHosts( [ [