0

Is there a way to escape colon and forward slash in params?

Uri.https('example.com', '/api', {
          'response_type': 'code',
          'client_id': 'id',
          'redirect_uri': 'https://www.google.com',
        })

The above turns into this: https%3A%2F%2Fwww.google.com

Encoding doesn't work

final redirect = Uri.encodeFull('https://www.google.com');
final uri = Uri.https('example.com', '/api', {'redirect_uri': redirect});

print(redirect); // https://www.google.com
print(uri.query); // redirect_uri=https%3A%2F%2Fwww.google.com
moon
  • 1,702
  • 3
  • 19
  • 35

1 Answers1

1

Anything you give to that function is urlencoded, because HTTP. It seems you need to urldecode it before you use it in your scenario. This should help https://stackoverflow.com/a/17407240/679553

Here's how to decode a URLEncoded string

print(Uri.decodeFull(uri.query));
Gazihan Alankus
  • 11,256
  • 7
  • 46
  • 57
  • "does not work" won't get you very far in getting help. see for yourself here: https://www.urldecoder.org/ – Gazihan Alankus Feb 26 '20 at 06:34
  • I do appreciate your help but honestly, I don't see how your solution or general direction provided help guide me in resolving my problem. As I pointed out in the test case, the encoding and decoding didn't help. I don't know what more to say. If I am missing something obvious, please do let me know. – moon Feb 26 '20 at 18:10
  • 1
    You never tried to decode it. Add this to the end of your test case: `print(Uri.decodeFull(uri.query));`. – Gazihan Alankus Feb 26 '20 at 19:00
  • If you are trying to prevent encoding altogether, it's not possible. Like I said: because HTTP. More info here: https://stackoverflow.com/a/2949359/679553 – Gazihan Alankus Feb 26 '20 at 19:05
  • That's much simpler than I thought, that line is all I needed. Thank you! Do you mind editing your answer to include that? I will accept it. – moon Feb 26 '20 at 20:56
  • @LuckyGuess how does this solve any problem? query is still getting encoded and getting converted to "https%3A%2F%2Fwww.google.com". Please help me if I am missing something. – Ujjwal Raijada Mar 24 '21 at 11:50