utils
utils copied to clipboard
Strings::webalize($haystack, '-') generates duplicate minus
Version: v3.2.7
Bug Description
Helper webalize with charlist parameter - generates duplicated minus in output:
Steps To Reproduce
$title = 'Title with - minus';
echo Strings::webalize($title); // title-with-minus
echo Strings::webalize($title, '-'); // title-with---minus
Expected Behavior
The output string should never contain two minus signs next to each other.
For example, when writing articles and an improperly chosen input string, it is possible to generate several minuses side by side.
Possible Solution
Add this regex:
$s = self::pcre('preg_replace', ['#-+#', '-', $s]);
Thanks.
Could you send a pull request?
Btw, what's the point of the minus character in charlist?
The minus sign could be inserted as a user input in the administration.
I think it should always be ensured that the function never returns two consecutive minus signs, even if it gets the wrong input.
I think the current behaviour is correct.