omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
258 stars 115 forks source link

Invalid Boolean parsing from #78

Closed laurentmuller closed 5 years ago

laurentmuller commented 5 years ago

When parsing Parameters to create a DataTableQuery, the values (like 'searchable' or 'orderable') are cast to a boolean with code like:

(bool) $column['orderable']

But the parameter value can only be the literal 'true' or 'false' and when cast, it returns true.

A bug fix is to test the literal value with code like:

'true' === $column['orderable']

or

filter_var($column['orderable'], FILTER_VALIDATE_BOOLEAN)

Tested with Symfony v3.4.24 and PHP v7.2.14.

curry684 commented 5 years ago

What problem would this fix?

laurentmuller commented 5 years ago

The "orderable" or "searchable" values are string (either "true" or "false") and when You cast a non-empty string to a bool value, the returned value is always true.

So (bool)"true" return true and (bool)"false" return also true ! It is because You must check the string value.

See: PHP Documentation

MaximePinot commented 5 years ago

Hi,

When are these values string?

https://github.com/omines/datatables-bundle/blob/33fb34a71705f92c11e689f70c74e378ce57e44d/src/Column/AbstractColumn.php#L135-L138

curry684 commented 5 years ago

I am aware of how type juggling and casting work in PHP, but as shown above those properties can never contain string values, as enforced by the Symfony OptionsResolver component. The null fallbacks are sane defaults also returning in correct boolean values.

https://github.com/omines/datatables-bundle/blob/33fb34a71705f92c11e689f70c74e378ce57e44d/src/Column/AbstractColumn.php#L206-L220

laurentmuller commented 5 years ago

Sorry, sorry and again sorry.

I wrote this issue in the wrong repository !

curry684 commented 5 years ago

Right 😆