-
Notifications
You must be signed in to change notification settings - Fork 981
Added ELASTIC_CLIENT_URL_PLUS_AS_SPACE env variable for URL encode #1303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fac07fd
Added ES_URL_PLUS_AS_SPACE env variable for URL encode
ezimuel 5a8ea51
Updated phpstan + fixed minor issues
ezimuel d895b6a
Changed env variable in ELASTIC_CLIENT_URL_PLUS_AS_SPACE
ezimuel f72234d
Refactored the test job for github action
ezimuel c7b05ee
Removed duplicate task
ezimuel 8f95de5
Revert ELASTICSEARCH_URL parameter
ezimuel 2dc2226
Added PHP 8.2 in CI
ezimuel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?php | ||
| /** | ||
| * Elasticsearch PHP client | ||
| * | ||
| * @link https://github.com/elastic/elasticsearch-php/ | ||
| * @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co) | ||
| * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 | ||
| * @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1 | ||
| * | ||
| * Licensed to Elasticsearch B.V under one or more agreements. | ||
| * Elasticsearch B.V licenses this file to you under the Apache 2.0 License or | ||
| * the GNU Lesser General Public License, Version 2.1, at your option. | ||
| * See the LICENSE file in the project root for more information. | ||
| */ | ||
| declare(strict_types = 1); | ||
|
|
||
| namespace Elasticsearch; | ||
|
|
||
| class Utility | ||
| { | ||
| const ENV_URL_PLUS_AS_SPACE = 'ES_URL_PLUS_AS_SPACE'; | ||
|
|
||
| /** | ||
| * Get the ENV variable with a thread safe fallback criteria | ||
| * @see https://github.com/elastic/elasticsearch-php/issues/1237 | ||
| * | ||
| * @return string | false | ||
| */ | ||
| public static function getEnv(string $env) | ||
| { | ||
| return $_SERVER[$env] ?? $_ENV[$env] ?? getenv($env); | ||
| } | ||
|
|
||
| /** | ||
| * Encode a string in URL using urlencode() or rawurlencode() | ||
| * according to env variable ES_URL_PLUS_AS_SPACE. | ||
| * If ES_URL_PLUS_AS_SPACE is true use urlencode(), otherwise rawurlencode() | ||
| * | ||
| * @see https://github.com/elastic/elasticsearch-php/issues/1278 | ||
| */ | ||
| public static function urlencode(string $url): string | ||
| { | ||
| return self::getEnv(self::ENV_URL_PLUS_AS_SPACE) === 'true' | ||
| ? rawurlencode($url) | ||
| : urlencode($url); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| <?php | ||
| /** | ||
| * Elasticsearch PHP client | ||
| * | ||
| * @link https://github.com/elastic/elasticsearch-php/ | ||
| * @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co) | ||
| * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 | ||
| * @license https://www.gnu.org/licenses/lgpl-2.1.html GNU Lesser General Public License, Version 2.1 | ||
| * | ||
| * Licensed to Elasticsearch B.V under one or more agreements. | ||
| * Elasticsearch B.V licenses this file to you under the Apache 2.0 License or | ||
| * the GNU Lesser General Public License, Version 2.1, at your option. | ||
| * See the LICENSE file in the project root for more information. | ||
| */ | ||
|
|
||
|
|
||
| declare(strict_types = 1); | ||
|
|
||
| namespace Elasticsearch\Tests; | ||
|
|
||
| use Elasticsearch\Utility; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| class UtilityTest extends TestCase | ||
| { | ||
| public function tearDown(): void | ||
| { | ||
| unset($_SERVER[Utility::ENV_URL_PLUS_AS_SPACE]); | ||
| unset($_ENV[Utility::ENV_URL_PLUS_AS_SPACE]); | ||
| putenv(Utility::ENV_URL_PLUS_AS_SPACE); | ||
| } | ||
|
|
||
| public function testGetEnvWithDollarServer() | ||
| { | ||
| $_SERVER[Utility::ENV_URL_PLUS_AS_SPACE] = 'true'; | ||
| $this->assertEquals('true', Utility::getEnv(Utility::ENV_URL_PLUS_AS_SPACE)); | ||
| } | ||
|
|
||
| public function testGetEnvWithDollarEnv() | ||
| { | ||
| $_ENV[Utility::ENV_URL_PLUS_AS_SPACE] = 'true'; | ||
| $this->assertEquals('true', Utility::getEnv(Utility::ENV_URL_PLUS_AS_SPACE)); | ||
| } | ||
|
|
||
| public function testGetEnvWithPutEnv() | ||
| { | ||
| putenv(Utility::ENV_URL_PLUS_AS_SPACE . '=true'); | ||
| $this->assertEquals('true', Utility::getEnv(Utility::ENV_URL_PLUS_AS_SPACE)); | ||
| } | ||
|
|
||
| public function testUrlencodeWithDefault() | ||
| { | ||
| $url = Utility::urlencode('bar baz'); | ||
| $this->assertEquals('bar+baz', $url); | ||
| } | ||
|
|
||
| public function testUrlencodeWithDollarServer() | ||
| { | ||
| $_SERVER[Utility::ENV_URL_PLUS_AS_SPACE] = 'true'; | ||
| $url = Utility::urlencode('bar baz'); | ||
| $this->assertEquals('bar%20baz', $url); | ||
| } | ||
|
|
||
| public function testUrlencodeWithDollarEnv() | ||
| { | ||
| $_ENV[Utility::ENV_URL_PLUS_AS_SPACE] = 'true'; | ||
| $url = Utility::urlencode('bar baz'); | ||
| $this->assertEquals('bar%20baz', $url); | ||
| } | ||
|
|
||
| public function testUrlencodeWithPutEnv() | ||
| { | ||
| putenv(Utility::ENV_URL_PLUS_AS_SPACE . '=true'); | ||
| $url = Utility::urlencode('bar baz'); | ||
| $this->assertEquals('bar%20baz', $url); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.