Feature #94162 » core-10.4.21.patch

Eric Bode, 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
111 111
        $slug = strip_tags($slug);
112 112
        // Convert some special tokens (space, "_" and "-") to the space character
113
        $dashes = ['-', '_'];
114
        $allowDashCharacters = (bool)($this->configuration['allowDashCharacters'] ?? false);
113 115
        $fallbackCharacter = (string)($this->configuration['fallbackCharacter'] ?? '-');
114
        $slug = preg_replace('/[ \t\x{00A0}\-+_]+/u', $fallbackCharacter, $slug);
116
        $fallbackCharacterPattern = $allowDashCharacters ? '/[ \t\x{00A0}+]+/u' : '/[ \t\x{00A0}\-+_]+/u';
117
        $slug = (string)preg_replace($fallbackCharacterPattern, $fallbackCharacter, $slug);
115 118
        if (!\Normalizer::isNormalized((string)$slug)) {
116 119
            $slug = \Normalizer::normalize((string)$slug);
......
122 125
        // The specCharsToASCII() converts "€" to "EUR"
123 126
        $slug = GeneralUtility::makeInstance(CharsetConverter::class)->specCharsToASCII('utf-8', $slug);
124
        // Get rid of all invalid characters, but allow slashes
125
        $slug = preg_replace('/[^\p{L}\p{M}0-9\/' . preg_quote($fallbackCharacter) . ']/u', '', $slug);
127
        // Get rid of all invalid characters, but allow slashes and dashes
128
        $validChars =  preg_quote($fallbackCharacter);
129
        if ($allowDashCharacters) {
130
            foreach ($dashes as $dash) {
131
                if ($dash !== $fallbackCharacter) {
132
                    $validChars .= preg_quote($dash);
133
                }
134
            }
135
        }
136
        $slug = (string)preg_replace('/[^\p{L}\p{M}0-9\/' . $validChars . ']/u', '', $slug);
126 137
        // Convert multiple fallback characters to a single one
127 138
        if ($fallbackCharacter !== '') {
128 139
            $slug = preg_replace('/' . preg_quote($fallbackCharacter) . '{2,}/', $fallbackCharacter, $slug);
129 140
        }
141
        // Convert multiple dashes to a single one
142
        if ($allowDashCharacters) {
143
            foreach ($dashes as $dash) {
144
                if ($dash !== $fallbackCharacter) {
145
                    $slug = (string)preg_replace('/' . preg_quote($dash) . '{2,}/', $dash, $slug);
146
                }
147
            }
148
        }
149

  
130 150
        // Ensure slug is lower cased after all replacement was done
131 151
        $slug = mb_strtolower($slug, 'utf-8');
132 152
        // Extract slug, thus it does not have wrapping fallback and slash characters
    (1-1/1)