geosolutions-it / MapStore2

The solution to create and share maps, dashboards, geostories with 3D support on the web. And it is open-source too!
https://mapstore.geosolutionsgroup.com/
Other
511 stars 398 forks source link

Different ajax requests for empty params using proxy #3144

Closed offtherailz closed 5 years ago

offtherailz commented 6 years ago

Description

Performing ajax ( ajax.js) requests with undefined params values causes different query strings using or not using proxy. If you use proxy, the params with undefined values will be added to the request this:

paramName1=&paramName2

This doesn't happen if the request is performed directly to the server. This is because of this intercept https://github.com/geosolutions-it/MapStore2/blob/master/web/client/libs/ajax.js#L117

Example:

with :

params : { CQL_FILTER: undefined}

You will have an additional parameter in queryString ...&CQL_FILTER= (empty). If the request is performed by axios without this intercept ,the undefined value is not used as parameter.

In case of Bug (otherwise remove this paragraph)

Browser Affected any

Steps to reproduce

offtherailz commented 5 years ago

Replicate this is not easy. You have to use ajax in a unit test, with a proxy or not and pass some parameter as undefined.

If you use te proxy or not you will have different behaiviours: In one case the parameters with undefined will not appear in the query string, in the other case will appear empty.

We have to avoid this second behavior and always exclude undefined params from the query string (or request, in general)

kasongoyo commented 5 years ago

@offtherailz I see axios not only ignore undefined params but also null params. It only allow params with value and empty string. I am going to fix proxy request to ignore both undefined and null params so that it align with default axios.

francoxyz commented 5 years ago

No steps for testers, developers only. See link for dev test

https://github.com/geosolutions-it/MapStore2/blob/9b442eb932482b3157b934b0803ac69c040f3c6e/web/client/libs/__tests__/ajax-test.js#L144