Skip to content

Commit

Permalink
rename methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Koen Eelen committed Sep 10, 2024
1 parent 78c08ba commit ad0d618
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions features/Steps/UtilitySteps.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ trait UtilitySteps
private bool $initialPreventDuplicatePlaceCreationValue;

/**
* @Given /^I create a name that includes special characters and keep it as "([^"]*)"$/
* @Given /^I create a name that includes special characters of elastic search and keep it as "([^"]*)"$/
*/
public function iCreateANameOfCharactersThatIncludesSpecialCharactersAndKeepItAs(string $variableName)
public function iCreateANameThatIncludesSpecialCharactersOfElasticSearchAndKeepItAs(string $variableName): void
{
$this->variableState->setVariable($variableName, '(a)![a]' . uniqid('', true));
}
Expand Down
2 changes: 1 addition & 1 deletion features/place/duplicate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Feature: Test creating places

Scenario: Be prevented from creating a new place if we already have one on that address when the the address contains special chars
Given I prevent duplicate place creation
Given I create a name that includes special characters and keep it as "name"
Given I create a name that includes special characters of elastic search and keep it as "name"
Given I create a minimal place and save the "id" as "originalPlaceId" then I should get a "201" response code
Then I wait for the place with url "/places/%{originalPlaceId}" to be indexed
Given I create a minimal place then I should get a "409" response code
Expand Down
11 changes: 4 additions & 7 deletions src/Place/ReadModel/Duplicate/UniqueAddressIdentifierFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function create(string $title, Address $address, string $currentUserId):
$this->getParts($title, $address, $currentUserId)
);

return mb_strtolower($this->escapeQueryChars(implode('_', array_filter($parts))));
return mb_strtolower($this->escapeReservedElasticsearchCharacters(implode('_', array_filter($parts))));
}

private function getParts(string $title, Address $address, string $currentUserId): array
Expand All @@ -31,15 +31,12 @@ private function getParts(string $title, Address $address, string $currentUserId
}

/**
* Escape special characters in the query string for Elasticsearch.
*
* @param string $query The raw query string.
* @return string The escaped query string.
* Escape reserved Elasticsearch characters in the query string for Elasticsearch.
*/
private function escapeQueryChars(string $query): string
private function escapeReservedElasticsearchCharacters(string $query): string
{
// List of special characters that need escaping
$specialChars = ['\\', '+', '-', '=', '&&', '||', '>', '<', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '/'];
$specialChars = ['\\', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '/'];

// Escape each character
foreach ($specialChars as $char) {
Expand Down

0 comments on commit ad0d618

Please sign in to comment.