Skip to content
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: make sure script and stack are both decoded before comparing #31037

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 >>
Expand Down
4 changes: 4 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 7 additions & 0 deletions packages/driver/cypress/e2e/issues/issue—31034.cy.js
Original file line number Diff line number Diff line change
@@ -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')
})
})
16 changes: 9 additions & 7 deletions packages/server/lib/privileged-commands/privileged-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading