laminas-filter
laminas-filter copied to clipboard
CamelCaseToDashFilter & numbers
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
@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
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!