Search code examples
typescriptwindowscmdspotifydeno

quotes turn into backslashes with Deno.Command


await new Deno.Command('cmd', {
    args: [
        '/c',
        'start',
        `https://accounts.spotify.com/authorize?${new URLSearchParams({
            client_id,
            response_type: 'code',
            redirect_uri: 'http://localhost:8080/callback',
            scope: 'user-library-read',
        })}`.replaceAll(/&/g, '"&"'),
    ],
    stdout: 'piped',
    stderr: 'piped',
}).output();

I am trying to open this URL in my browser in Deno on Windows. However, the URL that is opened is this:

https://accounts.spotify.com/authorize?client_id=x\&\response_type=code\&\redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fcallback\&\scope=user-library-read

where the " has been replaced with \. If I do not wrap the & in the URL parameters in quotes, then only one URL parameter gets opened in the browser like this:

https://accounts.spotify.com/authorize?client_id=x

I would like to open the URL in the browser with all parameters but I'm not sure how to go about this.


Solution

  • https://deno.land/api@v1.35.3?s=Deno.CommandOptions#prop_windowsRawArguments There's a flag to disable this behaviour.