Skip to content

Commit

Permalink
fix: escape backslashes in downloadFolder for Firefox on Windows #17896
Browse files Browse the repository at this point in the history
… (#23006)

* fix: escape backslashes in downloadFolder for Firefox on Windows

* fix import of doubleEscape in packages/server/lib/browsers/firefox.ts

Co-authored-by: Bill Glesias <[email protected]>

* don't run ls command on Windows

* Revert "don't run ls command on Windows"

This reverts commit deec721.

* chore: add unit test to verify double escape behavior

Co-authored-by: Bill Glesias <[email protected]>
Co-authored-by: Rachel <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2022
1 parent 4580330 commit f7dce39
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/server/lib/browsers/firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import getPort from 'get-port'
import path from 'path'
import urlUtil from 'url'
import { debug as launcherDebug, launch, LaunchedBrowser } from '@packages/launcher/lib/browsers'
import { doubleEscape } from '@packages/launcher/lib/windows'
import FirefoxProfile from 'firefox-profile'
import * as errors from '../errors'
import firefoxUtil from './firefox-util'
Expand Down Expand Up @@ -427,7 +428,7 @@ export async function open (browser: Browser, url, options: any = {}, automation
'network.proxy.http_port': +port,
'network.proxy.ssl_port': +port,
'network.proxy.no_proxies_on': '',
'browser.download.dir': options.downloadsFolder,
'browser.download.dir': os.platform() === 'win32' ? doubleEscape(options.downloadsFolder) : options.downloadsFolder,
})
}

Expand Down
17 changes: 17 additions & 0 deletions packages/server/test/unit/browsers/firefox_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,23 @@ describe('lib/browsers/firefox', () => {
})
})

// @see https://github.com/cypress-io/cypress/issues/17896
it('escapes the downloadsFolders path correctly when running on Windows OS', function () {
this.options.proxyServer = 'http://proxy-server:1234'
this.options.downloadsFolder = 'C:/Users/test/Downloads/My_Test_Downloads_Folder'
sinon.stub(os, 'platform').returns('win32')
const executeBeforeBrowserLaunchSpy = sinon.spy(utils, 'executeBeforeBrowserLaunch')

return firefox.open(this.browser, 'http://', this.options, this.automation).then(() => {
expect(executeBeforeBrowserLaunchSpy).to.have.been.calledWith(this.browser, sinon.match({
preferences: {
// NOTE: sinon.match treats the string itself as a regular expression. The backslashes need to be escaped.
'browser.download.dir': 'C:\\\\Users\\\\test\\\\Downloads\\\\My_Test_Downloads_Folder',
},
}), this.options)
})
})

it('updates the preferences', function () {
return firefox.open(this.browser, 'http://', this.options, this.automation).then(() => {
expect(FirefoxProfile.prototype.updatePreferences).to.be.called
Expand Down

5 comments on commit f7dce39

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f7dce39 Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.5.1/linux-x64/develop-f7dce3987640e2b934e43239bd6cb42a8909fb48/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f7dce39 Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.5.1/linux-arm64/develop-f7dce3987640e2b934e43239bd6cb42a8909fb48/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f7dce39 Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.5.1/darwin-arm64/develop-f7dce3987640e2b934e43239bd6cb42a8909fb48/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f7dce39 Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.5.1/darwin-x64/develop-f7dce3987640e2b934e43239bd6cb42a8909fb48/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on f7dce39 Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.5.1/win32-x64/develop-f7dce3987640e2b934e43239bd6cb42a8909fb48/cypress.tgz

Please sign in to comment.