laminas / laminas-filter

Programmatically filter and normalize data and files
https://docs.laminas.dev/laminas-filter/
BSD 3-Clause "New" or "Revised" License
77 stars 33 forks source link

CamelCaseToDashFilter & numbers #10

Open weierophinney opened 4 years ago

weierophinney commented 4 years ago

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

froschdesign commented 1 week ago

@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
gsteel commented 1 week ago

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!