amplify-swift
amplify-swift copied to clipboard
Using a semicolon in a value in QueryParameters suddenly doesn't work anymore
Describe the bug
I'm calling a REST API with some query parameters ([String : String]). The API call worked for months now. One value in the query is a string like "X;Y". The server now receives only X and not the entire string. I put this query dict in a RESTRequest that is simply passed to Amplify.API.get.
Any ideas what happened ? It might coincide with the update to 2.45.4 I did a few days ago.
PS: This suddenly became a huge issue, I realized I have values like this in 99% of the API calls. Having a ";" in any value in the query parameters, simply removes everything what's after the 1st semicolon. I tried encoding it (%3B), not encoding it, nothing works. Amplify just kills it.
Steps To Reproduce
- Access any REST API call with Amplify that requires queryParameters and send a value with a semicolon somewhere in the middle.
Expected behavior
The server should receive the entire string, not only what's before the semicolon.
Amplify Framework Version
2.45.4
Amplify Categories
API
Dependency manager
Swift PM
@dcristolovean Thanks for opening the issue, I will work on reproducing this in my local environment and get back to you.
I did log the url with an interceptor and it seems the values are sent correctly (I think), as "x;y;z". Still the server now says it only gets "x". From Android, my colleague encodes them (which I also tried) so he sends "x%3By%3Bz" which works on the server somehow. Android Amplify seems to leave them be and actually has this thing in the final URL.
The thing is I also tried to encode them, I can see the query parameters with %3B as soon as I pass them to Amplify, but the final url I see in the interceptor is still with ";"
So I would say double failure here :) . 1. Why does Amplify change my %3B to ";" in the final URL. 2. (this surely is not for you) Why does my AWS Rest API not understand "x;y" ?
Everything worked for weeks so far, just suddenly it doesn't work anymore.
@dcristolovean What was the version you upgraded from?
2.45.x ....something less than 4 :) I don't remember. 1, 2 or 3 :) It's SPM and I deleted the Derived Data completely for other reasons, so it just downloaded the new version by itself.
Is it possible that a previous Amplify version was just encoding the ";" by itself ? That would explain why my server worked for me, even if I never encoded myself the ";" ? And now the new version doesn't do that by default, as seen in the url i logged in the interceptor ? What's also different is that the Android Amplify does actually encode the ; in the final url.
Yeah.. That could definitely be possible, I don't see anything that changed from 2.45.0 to 2.45.4 that should affect encoding. Are you able to test this in the following 3 versions by manually setting the version in SPM?
- 244.0
- 2.43.0
- 2.42.0
And validate if you are seeing the same issue, atleast that would validate the hypothesis of something going wrong in one of the recent versions of Amplify Swift.
This is getting even more interesting:
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html The semicolon character (;) is not supported for any request URL query string and results in the data being split.
Nice. But.. the problem is that now I can't send ";" encoded, as seen, Amplify removes my encoding. Yes I will try to change the versions to see, not much else to do...
OK, more info:
-
2.42.0 still logs my URL with ";" So no point in testing the newer ones
-
THIS IS THE FIX, NOW IT WORKS:
class RESTInterceptor: URLRequestInterceptor {
func intercept(_ request: URLRequest) -> URLRequest {
var encodedRequest = request
let urlString = (request.url?.absoluteString ?? "").replacingOccurrences(of: ";", with: "%3B")
encodedRequest.url = URL(string: urlString)
return encodedRequest
}
}
Yes, this is the most horrific workaround you've ever seen, I know :). BUT IT WORKS. Considering I'm also hitting your AWS REST APIs, this is clearly a problem. It seems it never worked in Amplify, my bad. But it worked for years in AWSMobileClient, I was always sending "x;y;z" and the SDK was handling it correctly. And it works on Android, that SDK never replaces his encoding and leaves it as it is.
Let me know if you consider this an Amplify bug (which 100% it is :) ) and how to proceed from here.
@dcristolovean Thanks for getting back and providing these details.. I'll keep this issue open as a bug, as Amplify Swift seems to be not doing encoding correctly whereas Android does.
I'll keep this at relatively lower priority since you have workaround and its not blocking you.