dhis2/d2

Encoding failure when filtering

Awnage opened this issue · 2 comments

I have been trying to use d2 to find existing records that have standard html encoding issues:
d2.models.optionSet.filter().on('name').equals('A & B')

This will produce a network call like:
/api/optionSets?filter=name:eq:A%20&%20B&fields=:all
which will fail since the & was not encoded.

A normal solution would be to use encodeURIComponent on name but that results in "double encoding"
d2.models.optionSet.filter().on('name').equals(encodeURIComponent('A & B'))
api/optionSets?filter=name:eq:A%2520%2526%2520B&fields=:all

Thoughts?

This is working now on https://play.dhis2.org/dev/

Indeed, some old code did not encode the query string properly (it encoded the whole query string, not values individually). Make sure you are using the last release of each major version. For example, if you are using v26, note that 26.1.12 does not work well, but 26.2.1, does:

https://github.com/dhis2/d2/blob/v26.1.12/src/api/Api.js#L134
https://github.com/dhis2/d2/blob/v26.2.1/src/api/Api.js#L136