-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Modify doubleEscape to handle path with extra backslashes and launch edge without browser key #14723
fix: Modify doubleEscape to handle path with extra backslashes and launch edge without browser key #14723
Changes from 5 commits
4e16737
ac0307e
5df4808
d565ab2
e00640e
ad7174a
4873af0
fd9c0d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import _ from 'lodash' | ||
import { expect } from 'chai' | ||
import * as windowsHelper from '../../lib/windows' | ||
import { normalize } from 'path' | ||
import { normalize, win32 } from 'path' | ||
import { utils } from '../../lib/utils' | ||
import sinon, { SinonStub } from 'sinon' | ||
import { browsers } from '../../lib/browsers' | ||
|
@@ -14,7 +14,7 @@ import { detectByPath } from '../../lib/detect' | |
import { goalBrowsers } from '../fixtures' | ||
|
||
function stubBrowser (path: string, version: string) { | ||
path = normalize(path.replace(/\\/g, '\\\\')) | ||
path = doubleEscape(normalize(path)) | ||
|
||
;(utils.execa as unknown as SinonStub) | ||
.withArgs('wmic', ['datafile', 'where', `name="${path}"`, 'get', 'Version', '/value']) | ||
|
@@ -25,6 +25,10 @@ function stubBrowser (path: string, version: string) { | |
.resolves(true) | ||
} | ||
|
||
function doubleEscape (s: string) { | ||
return win32.join(...s.split(win32.sep)).replace(/\\/g, '\\\\') | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you just import this from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you mean Exported that function, used it in the test case and added its own test cases |
||
function detect (goalBrowsers: Browser[]) { | ||
return Bluebird.mapSeries(goalBrowsers, (browser) => { | ||
return windowsHelper.detect(browser) | ||
|
@@ -91,39 +95,45 @@ describe('windows browser detection', () => { | |
|
||
it('works with :browserName format in Windows', () => { | ||
sinon.stub(os, 'platform').returns('win32') | ||
stubBrowser(`${HOMEDIR}/foo/bar/browser.exe`, '100') | ||
let path = `${HOMEDIR}/foo/bar/browser.exe` | ||
let win10Path = doubleEscape(path) | ||
|
||
return detectByPath(`${HOMEDIR}/foo/bar/browser.exe:foo-browser`, goalBrowsers as Browser[]).then((browser) => { | ||
stubBrowser(path, '100') | ||
|
||
return detectByPath(`${path}:foo-browser`, goalBrowsers as Browser[]).then((browser) => { | ||
expect(browser).to.deep.equal( | ||
Object.assign({}, goalBrowsers.find((gb) => { | ||
return gb.name === 'foo-browser' | ||
}), { | ||
displayName: 'Custom Foo Browser', | ||
info: `Loaded from ${HOMEDIR}/foo/bar/browser.exe`, | ||
info: `Loaded from ${win10Path}`, | ||
custom: true, | ||
version: '100', | ||
majorVersion: 100, | ||
path: `${HOMEDIR}/foo/bar/browser.exe`, | ||
path: win10Path, | ||
}), | ||
) | ||
}) | ||
}) | ||
|
||
it('identifies browser if name in path', async () => { | ||
sinon.stub(os, 'platform').returns('win32') | ||
stubBrowser(`${HOMEDIR}/foo/bar/chrome.exe`, '100') | ||
let path = `${HOMEDIR}/foo/bar/chrome.exe` | ||
let win10Path = doubleEscape(path) | ||
|
||
stubBrowser(path, '100') | ||
|
||
return detectByPath(`${HOMEDIR}/foo/bar/chrome.exe`).then((browser) => { | ||
return detectByPath(path).then((browser) => { | ||
expect(browser).to.deep.equal( | ||
Object.assign({}, browsers.find((gb) => { | ||
return gb.name === 'chrome' | ||
}), { | ||
displayName: 'Custom Chrome', | ||
info: `Loaded from ${HOMEDIR}/foo/bar/chrome.exe`, | ||
info: `Loaded from ${win10Path}`, | ||
custom: true, | ||
version: '100', | ||
majorVersion: 100, | ||
path: `${HOMEDIR}/foo/bar/chrome.exe`, | ||
path: win10Path, | ||
}), | ||
) | ||
}) | ||
|
@@ -149,23 +159,74 @@ describe('windows browser detection', () => { | |
|
||
context('#getPathData', () => { | ||
it('returns path and browserKey given path with browser key', () => { | ||
const res = windowsHelper.getPathData('C:\\foo\\bar.exe:firefox') | ||
const browserPath = 'C:\\foo\\bar.exe' | ||
const res = windowsHelper.getPathData(`${browserPath}:firefox`) | ||
|
||
expect(res.path).to.eq('C:\\foo\\bar.exe') | ||
expect(res.path).to.eq(doubleEscape(browserPath)) | ||
expect(res.browserKey).to.eq('firefox') | ||
}) | ||
|
||
it('returns path and browserKey given path with a lot of slashes plus browser key', () => { | ||
const browserPath = 'C:\\\\\\\\foo\\\\\\bar.exe' | ||
const res = windowsHelper.getPathData(`${browserPath}:firefox`) | ||
|
||
expect(res.path).to.eq(doubleEscape(browserPath)) | ||
expect(res.browserKey).to.eq('firefox') | ||
}) | ||
|
||
it('returns path and browserKey given nix path with browser key', () => { | ||
const browserPath = 'C:/foo/bar.exe' | ||
const res = windowsHelper.getPathData(`${browserPath}:firefox`) | ||
|
||
expect(res.path).to.eq(doubleEscape(browserPath)) | ||
expect(res.browserKey).to.eq('firefox') | ||
}) | ||
|
||
it('returns path and chrome given just path', () => { | ||
const res = windowsHelper.getPathData('C:\\foo\\bar\\chrome.exe') | ||
const browserPath = 'C:\\foo\\bar\\chrome.exe' | ||
const res = windowsHelper.getPathData(browserPath) | ||
|
||
expect(res.path).to.eq(doubleEscape(browserPath)) | ||
expect(res.browserKey).to.eq('chrome') | ||
}) | ||
|
||
expect(res.path).to.eq('C:\\foo\\bar\\chrome.exe') | ||
it('returns path and chrome given just nix path', () => { | ||
const browserPath = 'C:/foo/bar/chrome.exe' | ||
const res = windowsHelper.getPathData(browserPath) | ||
|
||
expect(res.path).to.eq(doubleEscape(browserPath)) | ||
expect(res.browserKey).to.eq('chrome') | ||
}) | ||
|
||
it('returns path and edge given just path', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also use a test for msedge.exe - that is what #14716 is about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, updated |
||
const browserPath = 'C:\\foo\\bar\\edge.exe' | ||
const res = windowsHelper.getPathData(browserPath) | ||
|
||
expect(res.path).to.eq(doubleEscape(browserPath)) | ||
expect(res.browserKey).to.eq('edge') | ||
}) | ||
|
||
it('returns path and edge given just nix path', () => { | ||
const browserPath = 'C:/foo/bar/edge.exe' | ||
const res = windowsHelper.getPathData(browserPath) | ||
|
||
expect(res.path).to.eq(doubleEscape(browserPath)) | ||
expect(res.browserKey).to.eq('edge') | ||
}) | ||
|
||
it('returns path and firefox given just path', () => { | ||
const res = windowsHelper.getPathData('C:\\foo\\bar\\firefox.exe') | ||
const browserPath = 'C:\\foo\\bar\\firefox.exe' | ||
const res = windowsHelper.getPathData(browserPath) | ||
|
||
expect(res.path).to.eq(doubleEscape(browserPath)) | ||
expect(res.browserKey).to.eq('firefox') | ||
}) | ||
|
||
it('returns path and firefox given just nix path', () => { | ||
const browserPath = 'C:/foo/bar/firefox.exe' | ||
const res = windowsHelper.getPathData(browserPath) | ||
|
||
expect(res.path).to.eq('C:\\foo\\bar\\firefox.exe') | ||
expect(res.path).to.eq(doubleEscape(browserPath)) | ||
expect(res.browserKey).to.eq('firefox') | ||
}) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, I guess this does technically work for msedge.exe too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, keeping that
browserKey
edge for msedge.exe too as we useedge
everywhere else.