Skip to content

Commit

Permalink
Fix prependMissingScheme with underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
ihor-sviziev committed Sep 18, 2019
1 parent c40d3b3 commit 9c6e356
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Elasticsearch/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
13 changes: 12 additions & 1 deletion tests/Elasticsearch/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
[
[
Expand Down

0 comments on commit 9c6e356

Please sign in to comment.