Skip to content

Commit b35ec5e

Browse files
committed
Changed the settings of ELASTIC_CLIENT_URL_PLUS_AS_SPACE
1 parent 6e2967b commit b35ec5e

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/Elasticsearch/Utility.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ public static function getEnv(string $env)
4040
*/
4141
public static function urlencode(string $url): string
4242
{
43-
return self::getEnv(self::ENV_URL_PLUS_AS_SPACE) === 'true'
44-
? rawurlencode($url)
45-
: urlencode($url);
43+
$plusAsSpace = self::getEnv(self::ENV_URL_PLUS_AS_SPACE);
44+
return $plusAsSpace === false || $plusAsSpace === 'true'
45+
? urlencode($url)
46+
: rawurlencode($url);
4647
}
4748
}

tests/Elasticsearch/Tests/UtilityTest.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,51 @@ public function testGetEnvWithPutEnv()
4848
$this->assertEquals('true', Utility::getEnv(Utility::ENV_URL_PLUS_AS_SPACE));
4949
}
5050

51-
public function testUrlencodeWithDefault()
51+
public function testUrlWithPlusAsDefault()
5252
{
5353
$url = Utility::urlencode('bar baz');
5454
$this->assertEquals('bar+baz', $url);
5555
}
5656

57-
public function testUrlencodeWithDollarServer()
57+
public function testUrlWithPlusWithDollarServer()
5858
{
5959
$_SERVER[Utility::ENV_URL_PLUS_AS_SPACE] = 'true';
6060
$url = Utility::urlencode('bar baz');
61-
$this->assertEquals('bar%20baz', $url);
61+
$this->assertEquals('bar+baz', $url);
6262
}
6363

64-
public function testUrlencodeWithDollarEnv()
64+
public function testUrlWithPlusWithDollarEnv()
6565
{
6666
$_ENV[Utility::ENV_URL_PLUS_AS_SPACE] = 'true';
6767
$url = Utility::urlencode('bar baz');
68-
$this->assertEquals('bar%20baz', $url);
68+
$this->assertEquals('bar+baz', $url);
6969
}
7070

71-
public function testUrlencodeWithPutEnv()
71+
public function testUrlWithPlusWithPutEnv()
7272
{
7373
putenv(Utility::ENV_URL_PLUS_AS_SPACE . '=true');
7474
$url = Utility::urlencode('bar baz');
75+
$this->assertEquals('bar+baz', $url);
76+
}
77+
78+
public function testUrlWith2BWithDollarServer()
79+
{
80+
$_SERVER[Utility::ENV_URL_PLUS_AS_SPACE] = 'false';
81+
$url = Utility::urlencode('bar baz');
82+
$this->assertEquals('bar%20baz', $url);
83+
}
84+
85+
public function testUrlWith2BWithDollarEnv()
86+
{
87+
$_ENV[Utility::ENV_URL_PLUS_AS_SPACE] = 'false';
88+
$url = Utility::urlencode('bar baz');
89+
$this->assertEquals('bar%20baz', $url);
90+
}
91+
92+
public function testUrlWith2BWithPutEnv()
93+
{
94+
putenv(Utility::ENV_URL_PLUS_AS_SPACE . '=false');
95+
$url = Utility::urlencode('bar baz');
7596
$this->assertEquals('bar%20baz', $url);
7697
}
7798
}

0 commit comments

Comments
 (0)