Skip to content

Commit

Permalink
fix: Encode fileServerFolder to fix #25839 (#29162)
Browse files Browse the repository at this point in the history
* fix: Encode fileServerFolder to fix #25839

* fix: Encode fileServerFolder to fix #25839 add changelog

* update unit tests

* adjust CHANGELOG location

* Update packages/server/test/unit/config_spec.js

* Fix changelog entry placement

* Fix some bugs to pass the test case

* maintain a test case

* Fix changelog entry

* added integration test and updated to use encodeURI

* Update cli/CHANGELOG.md

---------

Co-authored-by: Jennifer Shehane <[email protected]>
Co-authored-by: Jennifer Shehane <[email protected]>
Co-authored-by: Matt Schile <[email protected]>
Co-authored-by: Matt Schile <[email protected]>
  • Loading branch information
5 people authored May 21, 2024
1 parent 297abbb commit 3a3d877
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _Released 5/21/2024 (PENDING)_
- Fixed an issue where orphaned Electron processes were inadvertently terminating the browser's CRI client. Fixes [#28397](https://github.com/cypress-io/cypress/issues/28397). Fixed in [#29515](https://github.com/cypress-io/cypress/pull/29515).
- Fixed an issue where Cypress would use the wrong URL to upload Test Replay recordings when it wasn't able to determine the upload URL. It now displays an error when the upload URL cannot be determined, rather than a "Request Entity Too Large" error. Addressed in [#29512](https://github.com/cypress-io/cypress/pull/29512).
- Fixed an issue where Cypress was unable to search in the Specs list for files or folders containing numbers. Fixes [#29034](https://github.com/cypress-io/cypress/issues/29034).
- Fixed an issue setting the `x-cypress-file-path` header when there are invalid header characters in the file path. Fixes [#25839](https://github.com/cypress-io/cypress/issues/25839).
- Fixed the display of some command assertions. Fixed in [#29517](https://github.com/cypress-io/cypress/pull/29517).

**Dependency Updates:**
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/file_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const onRequest = function (req, res, expectedToken, fileServerFolder) {
// %20 with white space
const file = decodeURI(url.parse(path.join(...args)).pathname)

res.setHeader('x-cypress-file-path', file)
res.setHeader('x-cypress-file-path', encodeURI(file))

return send(req, url.parse(req.url).pathname, {
root: path.resolve(fileServerFolder),
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/server-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ export class ServerBase<TSocket extends SocketE2E | SocketCt> {

if (fp) {
// if so we know this is a local file request
details.filePath = fp
details.filePath = decodeURI(fp)
}

debug('setting details resolving url %o', details)
Expand Down
26 changes: 24 additions & 2 deletions packages/server/test/integration/http_requests_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3851,13 +3851,13 @@ describe('Routes', () => {
})

context('file requests', () => {
beforeEach(function () {
function setupProject ({ fileServerFolder }) {
Fixtures.scaffold()

return this.setup('/index.html', {
projectRoot: Fixtures.projectPath('no-server'),
config: {
fileServerFolder: 'dev',
fileServerFolder,
specPattern: 'my-tests/**/*',
supportFile: false,
},
Expand All @@ -3883,6 +3883,12 @@ describe('Routes', () => {
expect(res.headers['last-modified']).to.exist
})
})
}

beforeEach(function () {
this.setupProject = setupProject.bind(this)

return this.setupProject({ fileServerFolder: 'dev' })
})

it('sets etag', function () {
Expand Down Expand Up @@ -3953,7 +3959,23 @@ describe('Routes', () => {
})
.then((res) => {
expect(res.statusCode).to.eq(200)
expect(res.headers).to.have.property('x-cypress-file-path', encodeURI(`${Fixtures.projectPath('no-server')}/dev/a space/foo.txt`))
expect(res.body).to.eq('foo')
})
})

it('can serve files with special characters in the fileServerFolder path', async function () {
await this.setupProject({ fileServerFolder: `dev/_ :;.,"'!(){}[]@<>=-+*$&\`|~^ĵ符` })

return this.rp({
url: `${this.proxy}/foo.txt`,
headers: {
'Accept-Encoding': 'identity',
},
})
.then((res) => {
expect(res.statusCode).to.eq(200)
expect(res.headers).to.have.property('x-cypress-file-path', encodeURI(`${Fixtures.projectPath('no-server')}/dev/_ :;.,"'!(){}[]@<>=-+*$&\`|~^ĵ符/foo.txt`))
expect(res.body).to.eq('foo')
})
})
Expand Down
6 changes: 6 additions & 0 deletions packages/server/test/unit/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@ describe('lib/config', () => {
return this.expectValidationFails('the value was: true')
})
})

it('passes if a string contains encoded special characters', function () {
this.setup({ fileServerFolder: encodeURI('/specialCharacters/无法解析的特殊字符') })

return this.expectValidationPasses()
})
})

context('fixturesFolder', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
index.html content
</body>
</html>

4 comments on commit 3a3d877

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3a3d877 May 21, 2024

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.9.1/linux-arm64/develop-3a3d877980c91a5a492eb65df7f43a81503b4d08/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3a3d877 May 21, 2024

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.9.1/linux-x64/develop-3a3d877980c91a5a492eb65df7f43a81503b4d08/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3a3d877 May 21, 2024

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.9.1/darwin-arm64/develop-3a3d877980c91a5a492eb65df7f43a81503b4d08/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 3a3d877 May 21, 2024

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.9.1/darwin-x64/develop-3a3d877980c91a5a492eb65df7f43a81503b4d08/cypress.tgz

Please sign in to comment.