Skip to content

Commit f9e872d

Browse files
authored
fix: decode both script and stack before making comparison in the priv channel. If decode sequencing fails, return false (#31037)
1 parent 1fb489a commit f9e872d

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

.circleci/workflows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ windowsWorkflowFilters: &windows-workflow-filters
8282
- equal: [ develop, << pipeline.git.branch >> ]
8383
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
8484
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
85-
- equal: [ 'chore/browser_spike', << pipeline.git.branch >> ]
85+
- equal: [ 'fix/em_dash_priv_command', << pipeline.git.branch >> ]
8686
- matches:
8787
pattern: /^release\/\d+\.\d+\.\d+$/
8888
value: << pipeline.git.branch >>

cli/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
_Released 2/11/2025 (PENDING)_
55

6+
**Bugfixes:**
7+
8+
- 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).
9+
610
**Dependency Updates:**
711

812
- Upgraded `compression` from `1.7.4` to `1.7.5`. Addressed in [#31004](https://github.com/cypress-io/cypress/pull/31004).
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @see https://github.com/cypress-io/cypress/issues/31034
2+
describe('issue #31034', { browser: '!webkit' }, () => {
3+
it('is able to run privileged commands when there is a em dash (—) in the spec name', () => {
4+
cy.visit('/fixtures/files-form.html')
5+
cy.get('#basic').selectFile('cypress/fixtures/valid.json')
6+
})
7+
})

packages/server/lib/privileged-commands/privileged-channel.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,17 @@
9292
script = replace.call(script, queryStringRegex, '')
9393
}
9494

95-
// stack URLs come in URI encoded by default.
96-
// we need to make sure our script names are also URI encoded
97-
// so the comparisons match
98-
let scriptName = encodeURI(script)
95+
// stack URLs come in encoded by default (similar to URI but not entirely accurate).
96+
// we need to make sure our script and stack are both decoded entirely to make sure the comparisons are accurate.
97+
try {
98+
const decodedScript = decodeURIComponent(script)
9999

100-
// we do NOT want to encode backslashes (\) as this causes pathing issues on Windows
101-
scriptName = scriptName.replace(/%5C/g, '\\')
100+
const decodedStack = decodeURIComponent(err.stack)
102101

103-
return stringIncludes.call(err.stack, scriptName)
102+
return stringIncludes.call(decodedStack, decodedScript)
103+
} catch (e) {
104+
return false
105+
}
104106
})
105107

106108
return filteredLines.length > 0

0 commit comments

Comments
 (0)