0

My needs:

Open an external url in my vscode extension. The url to open contains a search param: redirect_uri=/client-redirect?client_type=vscode

Problem encountered:

I open the url by:

env.openExternal(Uri.parse(url))

Encode the value part or not, open the url, the redirect_uri part in address bar is always redirect_uri=/client-redirect%253Fclient_type=vscode. If I click 'Copy' instead 'Open', the redirect_uri part is always redirect_uri=/client-redirect%3Fclient_type=vscode

The ? was encoded once or twice but / and = was not encoded. For comparsion, the correct encoding should be redirect_uri=%2Fclient-redirect%3Fclient_type%3Dvscode

I think the core problem is the Uri.parse and ext.OpenEnternal re-parse the url even it's already correctly encoded. I need a solution to open url directly without extra parse.

Temp solutions I found:

I can use open or system command instead of openExternal:

open(manullyEncodedUrl); // open moudle from node

// or use system command
// openUrlByCommand(manullyEncodedUrl); // open by 'open url' or 'start url' or 'xdg-open url' depends on os

The temp solutions can fullfill my needs for now, but the env.openExternal is still the ideal approach if possible, since it's offical and contains some special security check and logics for certain circumstances. So the final problem is: Is it possible to open such url by env.openExternal correctly

2
  • I think the problem is with Uri.parse, have you tried Uri.from (creating a URI from its component parts)? Commented Nov 7 at 11:47
  • @ninadepina Yes, the result is the same. The Uri.from receives a query string param which is the whole query part, no different with Uri.parse in parsing query. Commented Nov 9 at 3:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.