Most http libraries automatically handle URI encoding of query parameters. It would be expected that PineJS is able to accept URI encoded query parameters and decode them properly, however there seem to be some weird inconsistencies about when things need to be encoded and when they don't. For example, in open-balena-api, this request gets a Malformed url response:
The difference between the two is the / in device_type_alias/any being encoded as %2f. In fact, encoding any of /, (, ), or : in the filter value results in a Malformed url response but ' can be encoded as %27 and spaces as + or %20 without issue (or even not encoded), for example all of these fail:
Most http libraries automatically handle URI encoding of query parameters. It would be expected that PineJS is able to accept URI encoded query parameters and decode them properly, however there seem to be some weird inconsistencies about when things need to be encoded and when they don't. For example, in open-balena-api, this request gets a
Malformed url
response:whereas this works fine:
The difference between the two is the
/
indevice_type_alias/any
being encoded as%2f
. In fact, encoding any of/
,(
,)
, or:
in thefilter
value results in aMalformed url
response but'
can be encoded as%27
and spaces as+
or%20
without issue (or even not encoded), for example all of these fail:I could be wrong, but the issue seems to be that this
complex url
check happens BEFORE a call todecodeURIComponent
: https://github.com/balena-io/pinejs/blob/ca446d988dc0f6fb4e55f0bd23b545ec3b5ab618/src/sbvr-api/uri-parser.ts#L100This means that when the
/
,(
,)
, or:
are URI encoded, it skips straight to line 137 and callsparseOdata
without ever callingdecodeURIComponent
: https://github.com/balena-io/pinejs/blob/ca446d988dc0f6fb4e55f0bd23b545ec3b5ab618/src/sbvr-api/uri-parser.ts#L137On the other path, inside the if statement, OData parsing is done with the URI decoded params: https://github.com/balena-io/pinejs/blob/ca446d988dc0f6fb4e55f0bd23b545ec3b5ab618/src/sbvr-api/uri-parser.ts#L119-L125