eclipse-ditto/ditto-clients

[JS] Eq filter not working for boolean values

vavido opened this issue · 2 comments

When crating a filter in the JS client via the Eq filter interface and passing a boolean value, the filter is not correctly parsed by ditto.
Example:

Eq('attributes/active', true)

The problem seems to be that the value is always put in quotes, but ditto then treats it as a string and the type comparision fails (by design).
When the same filter is manually sent to ditto but with the quotes removed (i.e. eq('attributes/active', true) instead of eq('attributes/active', "true")) the filter works as expected.

I only tested & verified this for the Eq filter and boolean values, but I believe other filters and primitive types (number, object) will have the same problem.

Line at fault:
https://github.com/eclipse/ditto-clients/blob/a5735ed1aafad7f743f4a3cca501c9d98e1bc277/javascript/lib/api/src/options/filter.options.ts#L205

Nice catch, thank you for adding an issue for this. This can probably be fixed by accepting value: any and checking with typeof how the value should be "serialized" for the filter.
Would you be willing to create a PR for this?

Yes I plan on creating a PR for this, but it could take until the beginning of next week until I get around to tackling this.