infinitered / apisauce

Axios + standardized errors + request/response transforms.
MIT License
2.8k stars 184 forks source link

Weird behaviour with urls after updating to Xcode 15 #320

Open saransh-malik opened 1 year ago

saransh-malik commented 1 year ago

Facing a very strange issue after upgrading to Xcode 15. All the urls that have query params in the url, have the percentage symbol encoded twice, so with Xcode 14.3, this was how the url looked https://test.com/organizations/1/pins?$filters=%7B%22mapped%22:true,%22entities%22:%7B%22accounts%22:%7B%22includeGroups%22:true%7D,%22contacts%22:%7B%22includeGroups%22:true%7D%7D,%22includeCustomFields%22:true,%22pinLegends%22:%7B%22accounts%22:%7B%22shape%22:645981,%22color%22:645680%7D,%22contacts%22:%7B%22shape%22:645696,%22color%22:645732%7D%7D%7D&$order=%7B%22point%22:%5B77.191642,28.60893931596358%5D,%22unit%22:%22miles%22%7D&$limit=100

and then with Xcode 15, same url with no changes gets converted as this https://test.com/organizations/1/pins?$filters=%257B%2522mapped%2522:true,%2522entities%2522:%257B%2522accounts%2522:%257B%2522includeGroups%2522:true%257D,%2522contacts%2522:%257B%2522includeGroups%2522:true%257D%257D,%2522includeCustomFields%2522:true,%2522pinLegends%2522:%257B%2522accounts%2522:%257B%2522shape%2522:501951,%2522color%2522:593346%257D,%2522contacts%2522:%257B%2522shape%2522:517158,%2522color%2522:608557%257D%257D%257D&$order=%257B%2522point%2522:%5B-122.406417,37.785834%5D,%2522unit%2522:%2522miles%2522%257D&$limit=100

Notice how every percentage symbol has been encoded to %25 making the url invalid.

I did no changes and as soon as we revert back to Xcode 14.3 everything works fine again. Any idea what is causing this and how do we fix this?

Not sure, if this is linked to library but since we use this to send all requests was wondering if encoding happens at library level or native level.

jeveloper commented 10 months ago

I found the same issue

zenjedi commented 7 months ago

@saransh-malik @jeveloper were you able to find a way out?

saransh-malik commented 7 months ago

@saransh-malik @jeveloper were you able to find a way out?

Yes, you need to use paramSearlizer prop and format the urls on your own that gets it working.

zenjedi commented 7 months ago

Can you share a code snippet please?

saransh-malik commented 6 months ago

Can you share a code snippet please?

Yup this is how I am doing it currently

paramsSerializer: params => {
        let result = ''
        Object.keys(params ?? {}).forEach(key => {
          if (
            typeof params?.[key] === 'object' &&
            params?.[key] &&
            Object.keys(params?.[key] ?? {})
          ) {
            result += `${key}=${encodeURIComponent(
              JSON.stringify(params[key])
            )}&`
          } else if (params[key] !== undefined) {
            result += `${key}=${encodeURIComponent(params[key])}&`
          }
        })
        return result?.substring(0, result?.length - 1)
      },
zenjedi commented 6 months ago

Thanks @saransh-malik . I can confirm your serializer code works. Thanks and cheers! 👍