From 9c06d2af39561204d08470f778b5ab13604cc88c Mon Sep 17 00:00:00 2001 From: AtofStryker Date: Thu, 6 Feb 2025 10:50:09 -0500 Subject: [PATCH] fix: decode both script and stack before making comparison in the priv channel. If decode sequencing fails, return false --- .circleci/workflows.yml | 2 +- cli/CHANGELOG.md | 4 ++++ .../e2e/issues/issue\342\200\22431034.cy.js" | 7 +++++++ .../privileged-commands/privileged-channel.js | 16 +++++++++------- 4 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 "packages/driver/cypress/e2e/issues/issue\342\200\22431034.cy.js" diff --git a/.circleci/workflows.yml b/.circleci/workflows.yml index bab7f645bde3..9e67520c5fa9 100644 --- a/.circleci/workflows.yml +++ b/.circleci/workflows.yml @@ -82,7 +82,7 @@ windowsWorkflowFilters: &windows-workflow-filters - equal: [ develop, << pipeline.git.branch >> ] # use the following branch as well to ensure that v8 snapshot cache updates are fully tested - equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ] - - equal: [ 'chore/browser_spike', << pipeline.git.branch >> ] + - equal: [ 'fix/em_dash_priv_command', << pipeline.git.branch >> ] - matches: pattern: /^release\/\d+\.\d+\.\d+$/ value: << pipeline.git.branch >> diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index d05ea6b51330..c5f9c8d4257e 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -3,6 +3,10 @@ _Released 2/11/2025 (PENDING)_ +**Bugfixes:** + +- Fixed an issue in Cypress [`14.0.2`](https://docs.cypress.io/guides/references/changelog#14-0-2) where privileged commands did not run correctly when a spec file or support file contained certain encoded characters. Fixes [#31034](https://github.com/cypress-io/cypress/issues/31034) and [#31060](https://github.com/cypress-io/cypress/issues/31060). + **Dependency Updates:** - Upgraded `compression` from `1.7.4` to `1.7.5`. Addressed in [#31004](https://github.com/cypress-io/cypress/pull/31004). diff --git "a/packages/driver/cypress/e2e/issues/issue\342\200\22431034.cy.js" "b/packages/driver/cypress/e2e/issues/issue\342\200\22431034.cy.js" new file mode 100644 index 000000000000..c82f00662a1a --- /dev/null +++ "b/packages/driver/cypress/e2e/issues/issue\342\200\22431034.cy.js" @@ -0,0 +1,7 @@ +// @see https://github.com/cypress-io/cypress/issues/31034 +describe('issue #31034', { browser: '!webkit' }, () => { + it('is able to run privileged commands when there is a em dash (—) in the spec name', () => { + cy.visit('/fixtures/files-form.html') + cy.get('#basic').selectFile('cypress/fixtures/valid.json') + }) +}) diff --git a/packages/server/lib/privileged-commands/privileged-channel.js b/packages/server/lib/privileged-commands/privileged-channel.js index 7ebea830d47a..1d7c643f5877 100644 --- a/packages/server/lib/privileged-commands/privileged-channel.js +++ b/packages/server/lib/privileged-commands/privileged-channel.js @@ -92,15 +92,17 @@ script = replace.call(script, queryStringRegex, '') } - // stack URLs come in URI encoded by default. - // we need to make sure our script names are also URI encoded - // so the comparisons match - let scriptName = encodeURI(script) + // stack URLs come in encoded by default (similar to URI but not entirely accurate). + // we need to make sure our script and stack are both decoded entirely to make sure the comparisons are accurate. + try { + const decodedScript = decodeURIComponent(script) - // we do NOT want to encode backslashes (\) as this causes pathing issues on Windows - scriptName = scriptName.replace(/%5C/g, '\\') + const decodedStack = decodeURIComponent(err.stack) - return stringIncludes.call(err.stack, scriptName) + return stringIncludes.call(decodedStack, decodedScript) + } catch (e) { + return false + } }) return filteredLines.length > 0