Closed khalilsarwari closed 3 years ago
@khalilsarwari
Thank you for your contribution!
perhaps this file really shouldn't be touched
Yes, we cannot edit generated files.
it should be done some other way?
We can use the Transport
parameter to do this as shown in this example. The parameter can be added to this line.
cc @v-byte-cpu
Thanks for the pointers @kishorenc, I'll be sure not to edit the generated files then. I tried adding a transport wrapper at the line you suggested, but it comes too late I believe. The request url given as input to the transport wrapper is already deformed due to the parsing error taking place earlier.
For example, when I add the transport wrapper, the request URL is:
/search?+label_names%3A=%5Bnews%5D&filter_by=created_at%3A%3E%3D300
where the intended filter by is created_at:>=300 && label_names:=[news]
The start of the block here has the correct value for filter by, and by the end of that if block, the query values are incorrectly added. This all takes place before reaching the transport wrapper I added at the line you mentioned.
Assuming we want *api.SearchCollectionParams
to remain as is and not require the user to specify the filter in an encoded way, there needs to be an encoding step between *api.SearchCollectionParams
being created and the aforementioned block being reached. If this is the case, I am not sure where the best place would be. Perhaps the line before here there could be a reformatting step where filter by is encoded?
@khalilsarwari
This all takes place before reaching the transport wrapper I added at the line you mentioned.
Got it.
Perhaps the line before here there could be a reformatting step where filter by is encoded?
Yes, I think this is a reasonable solution. Let's go ahead with that! We might have do the encoding for other parameters as well which might be affected (e.g sort_by
).
I've added the encoding for filter_by
and q
for now, for the other fields it seems unlikely that they would have a character that needs to be escaped (having a colon :
already is supported).
LGTM @khalilsarwari -- can we also add this test which was earlier used to catch this issue?
Any suggestions/comments @v-byte-cpu?
@kishorenc yes, we should add the mentioned test to check that the original issue was fixed.
I have added the test @kishorenc @v-byte-cpu (please let me know if this should have been done another way, or if there is anything else)
@khalilsarwari Looks great. My final question: is there a reason for adding the query escaping logic to the tests here: https://github.com/typesense/typesense-go/pull/77/commits/0335f5a43ee51d5bf4aca8253a9a9272b1080f61
Were the tests failing without this change?
Yes, the tests were failing without this change.
The changes made in this PR to typesense/documents.go
are not reached/executed by the mockAPIClient
, yet this is the earliest place that I think we could make the change.
Change Summary
The current parsing assumes it has been encoded/escaped already, so this change adds escaping. Seems to resolve #71 , though perhaps this file really shouldn't be touched and it should be done some other way?
PR Checklist