laminas-filter icon indicating copy to clipboard operation
laminas-filter copied to clipboard

CamelCaseToDashFilter & numbers

Open weierophinney opened this issue 5 years ago • 2 comments

Not sure if this is expected behavior but seems like a bug to me, but if you pass a string with numbers into CamelCaseToDashFilter the dash is not applied before a number, please see below for a failing unit test.

    public function testFilterSeparatesCamelCasedWordsContainingNumbersWithDashes()
    {
        $string   = 'ItIs2016';
        $filter   = new CamelCaseToDashFilter();
        $filtered = $filter($string);
        $this->assertNotEquals($string, $filtered);
        $this->assertEquals('It-Is-2016', $filtered);
    }

Originally posted by @joshhornby at https://github.com/zendframework/zend-filter/issues/33

weierophinney avatar Dec 31 '19 22:12 weierophinney

@gsteel Do we want this behaviour for this filter? Some code is already available: https://github.com/zendframework/zend-filter/pull/45

If we look at the filter for the opposite, then it would be consistent:

$filter = new Laminas\Filter\Word\DashToCamelCase();
$value  = 'foo-bar-123';
echo $filter->filter($value); // Output: FooBar123

froschdesign avatar Sep 04 '24 11:09 froschdesign

I think so - IMO ItIs2016 -> It-Is-2016 is what I'd expect the filter to do, so if it doesn't, now is a good time to fix that!

gsteel avatar Sep 04 '24 11:09 gsteel