Issue Bug Closed

#94693Slug fieldSeparator (and replacements) replaced by fallbackCharacter

Oliver N. 08/02/21, 20:43 updated 12/01/21, 13:49

Description

Example 1:

'config' => [
    'type' => 'slug',
    'generatorOptions' => [
        'fields' => ['field1','field2'],
        'fieldSeparator' => '-',
    ],
    'fallbackCharacter' => '.',
    'eval' => 'uniqueInSite'
],
Input field1    : Field-1
Input field2    : Field-2
Expected result : field.1-field.2
Generated result: field.1.field.2

Example 2:

'config' => [
    'type' => 'slug',
    'generatorOptions' => [
        'fields' => ['field1','field2'],
        'fieldSeparator' => '-',
        'replacements' => [
            '-' => '_'
        ],
    ],
    'fallbackCharacter' => '.',
    'eval' => 'uniqueInSite'
],
Input field1    : Field-1
Input field2    : Field-2
Expected result : field_1-field_2
Generated result: field.1.field.2

Function SlugHelper::sanitize is called in the end of the generate function leads into to this result.
The “magic” seems to happen in the code below – and showing which characters are affected.

// Convert some special tokens (space, "_" and "-") to the space character
$fallbackCharacter = (string)($this->configuration['fallbackCharacter'] ??
$slug = preg_replace('/[ \t\x{00A0}\-+_]+/u', $fallbackCharacter, $slug);
...
// Get rid of all invalid characters, but allow slashes
$slug = preg_replace('/[^\p{L}\p{M}0-9\/' . preg_quote($fallbackCharacter) . ']/u', '', $slug);

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.