utils icon indicating copy to clipboard operation
utils copied to clipboard

Strings::webalize($haystack, '-') generates duplicate minus

Open janbarasek opened this issue 3 years ago • 3 comments

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.

janbarasek avatar May 15 '22 08:05 janbarasek

Could you send a pull request?

dg avatar May 15 '22 13:05 dg

Btw, what's the point of the minus character in charlist?

dg avatar May 15 '22 13:05 dg

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.

janbarasek avatar May 15 '22 17:05 janbarasek

I think the current behaviour is correct.

dg avatar Sep 12 '22 23:09 dg