Skip to content

Commit

Permalink
Fix query strings on WSL (#171)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
tiagonapoli and sindresorhus committed Mar 9, 2020
1 parent 30f4abe commit 1e716b8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -46,6 +46,10 @@ module.exports = async (target, options) => {
// can be used on any platform.
if (options.url) {
target = encodeURI(target);

if (isWsl) {
target = target.replace(/&/g, '^&');
}
}

if (process.platform === 'darwin') {
Expand Down
12 changes: 10 additions & 2 deletions test.js
Expand Up @@ -79,11 +79,19 @@ test('open URL with query strings, spaces, pipes and a fragment', async () => {
});

if (isWsl) {
test('open URL in specified windows app given a wsl path to the app', async () => {
test('open URL in specified Windows app given a WSL path to the app', async () => {
await open('https://sindresorhus.com', {app: firefoxWslName});
});

test('open URL in specified windows app with arguments given a wsl path to the app', async () => {
test('open URL in specified Windows app with arguments given a WSL path to the app', async () => {
await open('https://sindresorhus.com', {app: [chromeWslName, '--incognito']});
});

test('open URL with query strings and spaces works with `url` option', async () => {
await open('https://sindresorhus.com/?abc=123&def=456&ghi=with spaces', {url: true});
});

test('open URL with query strings works with `url` option', async () => {
await open('https://sindresorhus.com/?abc=123&def=456', {url: true});
});
}

0 comments on commit 1e716b8

Please sign in to comment.