Skip to content

Commit

Permalink
IBX-6202: Fixed processing URL Alias schema pattern groups (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
kisztof authored Jul 27, 2023
1 parent 7688018 commit 3adc2af
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/lib/Repository/NameSchema/NameSchemaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ protected function tokenParts(string $token): array
*/
protected function filterNameSchema(string $nameSchema): array
{
$retNamePattern = '';
$retNamePattern = $nameSchema;
$foundGroups = preg_match_all('/\((.+)\)/U', $nameSchema, $groupArray);
$groupLookupTable = [];

Expand All @@ -341,7 +341,7 @@ protected function filterNameSchema(string $nameSchema): array

// Insert the group with its placeholder token
/** @var string $retNamePattern */
$retNamePattern = str_replace($group, $metaToken, $nameSchema);
$retNamePattern = str_replace($group, $metaToken, $retNamePattern);

// Remove the pattern "(" ")" from the tokens
$group = str_replace(['(', ')'], '', $group);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/Repository/NameSchema/SchemaIdentifierExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class SchemaIdentifierExtractor implements SchemaIdentifierExtractorInterf
*/
public function extract(string $schemaString): array
{
$allTokens = '/<([^>-]+)>/';
$allTokens = '/[<|\(]?([\w\d:_]+)[>\)]?/';

if (false === preg_match_all($allTokens, $schemaString, $matches)) {
return [];
Expand All @@ -46,7 +46,6 @@ public function extract(string $schemaString): array
$strategy = 'field';
}

$token = preg_replace('/[()<>\[\]]/', '', $token);
$strategyIdentifiers[$strategy][] = $token;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ public function getDataForTestExtract(): iterable
'custom' => ['bar'],
],
];

$schemaString = '<description|(<attribute:mouse_type> <attribute:mouse_weight>)>';
yield $schemaString => [
$schemaString,
[
'field' => ['description'],
'attribute' => ['mouse_type', 'mouse_weight'],
],
];
}

protected function setUp(): void
Expand All @@ -99,6 +108,7 @@ protected function setUp(): void
*/
public function testExtract(string $schemaString, array $expectedStrategyIdentifierMap): void
{
self::assertSame($expectedStrategyIdentifierMap, $this->extractor->extract($schemaString));
$extracted = $this->extractor->extract($schemaString);
self::assertSame($expectedStrategyIdentifierMap, $extracted);
}
}

0 comments on commit 3adc2af

Please sign in to comment.