Project

General

Profile

Feature #94162 » core-10.4.21.patch

Eric Harrer, 2021-12-06 15:09

View differences:

Classes/DataHandling/SlugHelper.php 2021-12-06 15:08:58.000000000 +0100 → Classes/DataHandling/SlugHelper.php 2021-12-06 15:48:14.000000000 +0100
$slug = strip_tags($slug);
// Convert some special tokens (space, "_" and "-") to the space character
$dashes = ['-', '_'];
$allowDashCharacters = (bool)($this->configuration['allowDashCharacters'] ?? false);
$fallbackCharacter = (string)($this->configuration['fallbackCharacter'] ?? '-');
$slug = preg_replace('/[ \t\x{00A0}\-+_]+/u', $fallbackCharacter, $slug);
$fallbackCharacterPattern = $allowDashCharacters ? '/[ \t\x{00A0}+]+/u' : '/[ \t\x{00A0}\-+_]+/u';
$slug = (string)preg_replace($fallbackCharacterPattern, $fallbackCharacter, $slug);
if (!\Normalizer::isNormalized((string)$slug)) {
$slug = \Normalizer::normalize((string)$slug);
......
// The specCharsToASCII() converts "€" to "EUR"
$slug = GeneralUtility::makeInstance(CharsetConverter::class)->specCharsToASCII('utf-8', $slug);
// Get rid of all invalid characters, but allow slashes
$slug = preg_replace('/[^\p{L}\p{M}0-9\/' . preg_quote($fallbackCharacter) . ']/u', '', $slug);
// Get rid of all invalid characters, but allow slashes and dashes
$validChars = preg_quote($fallbackCharacter);
if ($allowDashCharacters) {
foreach ($dashes as $dash) {
if ($dash !== $fallbackCharacter) {
$validChars .= preg_quote($dash);
}
}
}
$slug = (string)preg_replace('/[^\p{L}\p{M}0-9\/' . $validChars . ']/u', '', $slug);
// Convert multiple fallback characters to a single one
if ($fallbackCharacter !== '') {
$slug = preg_replace('/' . preg_quote($fallbackCharacter) . '{2,}/', $fallbackCharacter, $slug);
}
// Convert multiple dashes to a single one
if ($allowDashCharacters) {
foreach ($dashes as $dash) {
if ($dash !== $fallbackCharacter) {
$slug = (string)preg_replace('/' . preg_quote($dash) . '{2,}/', $dash, $slug);
}
}
}
// Ensure slug is lower cased after all replacement was done
$slug = mb_strtolower($slug, 'utf-8');
// Extract slug, thus it does not have wrapping fallback and slash characters
    (1-1/1)