From 787e65b8521116f19c85edb7f7a74292b061d1a6 Mon Sep 17 00:00:00 2001 From: Zzet-Z Date: Sun, 17 Mar 2024 10:42:33 +0800 Subject: [PATCH 01/11] fix: Encode fileServerFolder to fix #25839 --- packages/driver/src/cypress/error_messages.ts | 2 +- packages/server/lib/file_server.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/driver/src/cypress/error_messages.ts b/packages/driver/src/cypress/error_messages.ts index eafe770c003f..48be68dc41c1 100644 --- a/packages/driver/src/cypress/error_messages.ts +++ b/packages/driver/src/cypress/error_messages.ts @@ -2343,7 +2343,7 @@ export default { We failed looking for this file at the path: - ${obj.path} + ${decodeURIComponent(obj.path)} The internal Cypress web server responded with: diff --git a/packages/server/lib/file_server.js b/packages/server/lib/file_server.js index da04be9c4ee4..7d897499b808 100644 --- a/packages/server/lib/file_server.js +++ b/packages/server/lib/file_server.js @@ -54,7 +54,7 @@ module.exports = { const token = random.id(64) const srv = http.createServer(httpUtils.lenientOptions, (req, res) => { - return onRequest(req, res, token, fileServerFolder) + return onRequest(req, res, token, encodeURIComponent(fileServerFolder)) }) allowDestroy(srv) From 8294ce186aebe4df7dcaad9b54ec8da8ee30df42 Mon Sep 17 00:00:00 2001 From: Zzet-Z Date: Sun, 17 Mar 2024 11:04:39 +0800 Subject: [PATCH 02/11] fix: Encode fileServerFolder to fix #25839 add changelog --- cli/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 3b8ec7a5853d..d12a2f20be53 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -7,6 +7,10 @@ _Released 3/26/2024 (PENDING)_ - Updated jose from `4.11.2` to `4.15.5`. Addressed in [#29086](https://github.com/cypress-io/cypress/pull/29086). +**Bugfixes:** + +- Fixed an issue When there are special characters in our test folder path, sometimes the folder path is not parsed correctly.Fixes [#25839](https://github.com/cypress-io/cypress/issues/25839). + ## 13.7.0 _Released 3/13/2024_ From a581feeb25e213d32909048cc5722fe72bd7e607 Mon Sep 17 00:00:00 2001 From: Zzet-Z Date: Wed, 20 Mar 2024 09:33:08 +0800 Subject: [PATCH 03/11] update unit tests --- packages/server/test/unit/config_spec.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/server/test/unit/config_spec.js b/packages/server/test/unit/config_spec.js index 69ead5c1a0f4..ac4e1700743e 100644 --- a/packages/server/test/unit/config_spec.js +++ b/packages/server/test/unit/config_spec.js @@ -368,6 +368,12 @@ describe('lib/config', () => { return this.expectValidationFails('the value was: true') }) }) + + it('passes if a string contain invalid character but encode it', function () { + this.setup({ fileServerFolder: encodeURIComponent('/specialCharacters/无法解析的特殊字符') }) + + return this.expectValidationPasses() + }) }) context('fixturesFolder', () => { From 49e11fb2494ea35dffb9bc78e94724f9bbd9a03f Mon Sep 17 00:00:00 2001 From: Zzet-Z Date: Fri, 29 Mar 2024 09:38:40 +0800 Subject: [PATCH 04/11] adjust CHANGELOG location --- cli/CHANGELOG.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 9287145cd1f4..a4a10f5f2a48 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -7,6 +7,7 @@ _Released 4/2/2024 (PENDING)_ - Fixed an issue where Cypress was not executing beyond the first spec in `cypress run` for versions of Firefox 124 and up when a custom user agent was provided. Fixes [#29190](https://github.com/cypress-io/cypress/issues/29190). - Fixed a bug where fields using arrays in `cypress.config` are not correctly processed. Fixes [#27103](https://github.com/cypress-io/cypress/issues/27103). Fixed in [#27312](https://github.com/cypress-io/cypress/pull/27312). +- Fixed an issue When there are special characters in our test folder path, sometimes the folder path is not parsed correctly.Fixes [#25839](https://github.com/cypress-io/cypress/issues/25839). ## 13.7.1 @@ -21,10 +22,6 @@ _Released 3/21/2024_ - Updated jose from `4.11.2` to `4.15.5`. Addressed in [#29086](https://github.com/cypress-io/cypress/pull/29086). -**Bugfixes:** - -- Fixed an issue When there are special characters in our test folder path, sometimes the folder path is not parsed correctly.Fixes [#25839](https://github.com/cypress-io/cypress/issues/25839). - ## 13.7.0 _Released 3/13/2024_ From 3478cd188dc5e70accc74c208bc8f719a66c6381 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Wed, 17 Apr 2024 10:21:53 -0400 Subject: [PATCH 05/11] Update packages/server/test/unit/config_spec.js --- packages/server/test/unit/config_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/test/unit/config_spec.js b/packages/server/test/unit/config_spec.js index ac4e1700743e..dbffd694aabf 100644 --- a/packages/server/test/unit/config_spec.js +++ b/packages/server/test/unit/config_spec.js @@ -369,7 +369,7 @@ describe('lib/config', () => { }) }) - it('passes if a string contain invalid character but encode it', function () { + it('passes if a string contains an invalid character but encodes it', function () { this.setup({ fileServerFolder: encodeURIComponent('/specialCharacters/无法解析的特殊字符') }) return this.expectValidationPasses() From fe76f6e8cf59a60fd3dae586b9df1eb8b05b6078 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Wed, 17 Apr 2024 10:23:12 -0400 Subject: [PATCH 06/11] Fix changelog entry placement --- cli/CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index f98a62e24d24..170d5fbca31f 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -3,6 +3,10 @@ _Released 4/16/2024 (PENDING)_ +**Bugfixes:** + +- Fixed an issue when there are special characters in a test folder path where the folder path is sometimes not parsed correctly. Fixes [#25839](https://github.com/cypress-io/cypress/issues/25839). + **Misc:** - We now capture the [Semaphore](https://semaphoreci.com/) CI provider's environment variable [`SEMAPHORE_GIT_PR_NUMBER`](https://docs.semaphoreci.com/ci-cd-environment/environment-variables/#semaphore_git_pr_number) to display the linked PR number in the Cloud. Addressed in [#29314](https://github.com/cypress-io/cypress/pull/29314). @@ -33,7 +37,6 @@ _Released 4/2/2024_ - Fixed an issue where Cypress was not executing beyond the first spec in `cypress run` for versions of Firefox 124 and up when a custom user agent was provided. Fixes [#29190](https://github.com/cypress-io/cypress/issues/29190). - Fixed a bug where fields using arrays in `cypress.config` are not correctly processed. Fixes [#27103](https://github.com/cypress-io/cypress/issues/27103). Fixed in [#27312](https://github.com/cypress-io/cypress/pull/27312). -- Fixed an issue when there are special characters in a test folder path where the folder path is sometimes not parsed correctly. Fixes [#25839](https://github.com/cypress-io/cypress/issues/25839). - Fixed a hang where Cypress would run indefinitely while recording to the cloud when CDP disconnects during the middle of a test. Fixes [#29209](https://github.com/cypress-io/cypress/issues/29209). - Fixed a bug where option values containing quotation marks could not be selected. Fixes [#29213](https://github.com/cypress-io/cypress/issues/29213) From 1558179f98eeee65c174bd6f95fc95bd1ef9cff2 Mon Sep 17 00:00:00 2001 From: Zzet-Z Date: Wed, 24 Apr 2024 09:42:35 +0800 Subject: [PATCH 07/11] Fix some bugs to pass the test case --- packages/driver/src/cypress/error_messages.ts | 2 +- packages/server/lib/file_server.js | 4 ++-- packages/server/lib/server-base.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/driver/src/cypress/error_messages.ts b/packages/driver/src/cypress/error_messages.ts index cf511f499dfe..d77a28deaf29 100644 --- a/packages/driver/src/cypress/error_messages.ts +++ b/packages/driver/src/cypress/error_messages.ts @@ -2355,7 +2355,7 @@ export default { We failed looking for this file at the path: - ${decodeURIComponent(obj.path)} + ${obj.path} The internal Cypress web server responded with: diff --git a/packages/server/lib/file_server.js b/packages/server/lib/file_server.js index 7d897499b808..8e46af981b9e 100644 --- a/packages/server/lib/file_server.js +++ b/packages/server/lib/file_server.js @@ -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', encodeURIComponent(file)) return send(req, url.parse(req.url).pathname, { root: path.resolve(fileServerFolder), @@ -54,7 +54,7 @@ module.exports = { const token = random.id(64) const srv = http.createServer(httpUtils.lenientOptions, (req, res) => { - return onRequest(req, res, token, encodeURIComponent(fileServerFolder)) + return onRequest(req, res, token, fileServerFolder) }) allowDestroy(srv) diff --git a/packages/server/lib/server-base.ts b/packages/server/lib/server-base.ts index 01df2eae3696..4e0ea763cbc5 100644 --- a/packages/server/lib/server-base.ts +++ b/packages/server/lib/server-base.ts @@ -880,7 +880,7 @@ export class ServerBase { if (fp) { // if so we know this is a local file request - details.filePath = fp + details.filePath = decodeURIComponent(fp) } debug('setting details resolving url %o', details) From ff9b1d396d82080a2284ade47f5b6f26ca5deac8 Mon Sep 17 00:00:00 2001 From: Zzet-Z Date: Thu, 25 Apr 2024 09:38:41 +0800 Subject: [PATCH 08/11] maintain a test case --- packages/server/test/integration/http_requests_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/test/integration/http_requests_spec.js b/packages/server/test/integration/http_requests_spec.js index 9662d99c2a2c..1f2825b97ad0 100644 --- a/packages/server/test/integration/http_requests_spec.js +++ b/packages/server/test/integration/http_requests_spec.js @@ -3961,7 +3961,7 @@ describe('Routes', () => { it('sets x-cypress-file-path headers', function () { return this.rp(`${this.proxy}/assets/app.css`) .then((res) => { - expect(res.headers).to.have.property('x-cypress-file-path', `${Fixtures.projectPath('no-server')}/dev/assets/app.css`) + expect(res.headers).to.have.property('x-cypress-file-path', encodeURIComponent(`${Fixtures.projectPath('no-server')}/dev/assets/app.css`)) }) }) From f0c7b28f37125feb2ecb9cffd1a07567d1e03fbe Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Thu, 25 Apr 2024 10:42:52 -0400 Subject: [PATCH 09/11] Fix changelog entry --- cli/CHANGELOG.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 6b6664940820..cce4a6b28786 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -1,4 +1,12 @@ +## 13.8.2 + +_Released 5/7/2024 (PENDING)_ + +**Bugfixes:** + +- Fixed an issue when there are special characters in a test folder path where the folder path is sometimes not parsed correctly. Fixes [#25839](https://github.com/cypress-io/cypress/issues/25839). + ## 13.8.1 _Released 4/23/2024_ @@ -32,10 +40,6 @@ _Released 4/18/2024_ - Fixed a regression introduced in [`13.7.3`](https://docs.cypress.io/guides/references/changelog#13-7-3) where Cypress could hang handling long assertion messages. Fixes [#29350](https://github.com/cypress-io/cypress/issues/29350). -**Bugfixes:** - -- Fixed an issue when there are special characters in a test folder path where the folder path is sometimes not parsed correctly. Fixes [#25839](https://github.com/cypress-io/cypress/issues/25839). - **Misc:** - The [`SEMAPHORE_GIT_PR_NUMBER`](https://docs.semaphoreci.com/ci-cd-environment/environment-variables/#semaphore_git_pr_number) environment variable from [Semaphore](https://semaphoreci.com/) CI is now captured to display the linked PR number in the Cloud. Addressed in [#29314](https://github.com/cypress-io/cypress/pull/29314). From e569a7d84eebfce4026ea37f3b3ae90240558bca Mon Sep 17 00:00:00 2001 From: Matthew Schile Date: Thu, 16 May 2024 16:44:35 -0600 Subject: [PATCH 10/11] added integration test and updated to use encodeURI --- packages/server/lib/file_server.js | 2 +- packages/server/lib/server-base.ts | 2 +- .../test/integration/http_requests_spec.js | 28 +++++++++++++++++-- packages/server/test/unit/config_spec.js | 4 +-- .../foo.txt" | 1 + .../index.html" | 7 +++++ 6 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 "system-tests/projects/no-server/dev/_ :;.,\"'!(){}[]@<>=-+*$&`|~^\304\265\347\254\246/foo.txt" create mode 100644 "system-tests/projects/no-server/dev/_ :;.,\"'!(){}[]@<>=-+*$&`|~^\304\265\347\254\246/index.html" diff --git a/packages/server/lib/file_server.js b/packages/server/lib/file_server.js index 8e46af981b9e..ca5bcb5dd60f 100644 --- a/packages/server/lib/file_server.js +++ b/packages/server/lib/file_server.js @@ -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', encodeURIComponent(file)) + res.setHeader('x-cypress-file-path', encodeURI(file)) return send(req, url.parse(req.url).pathname, { root: path.resolve(fileServerFolder), diff --git a/packages/server/lib/server-base.ts b/packages/server/lib/server-base.ts index 4e0ea763cbc5..b9f6b78bf004 100644 --- a/packages/server/lib/server-base.ts +++ b/packages/server/lib/server-base.ts @@ -880,7 +880,7 @@ export class ServerBase { if (fp) { // if so we know this is a local file request - details.filePath = decodeURIComponent(fp) + details.filePath = decodeURI(fp) } debug('setting details resolving url %o', details) diff --git a/packages/server/test/integration/http_requests_spec.js b/packages/server/test/integration/http_requests_spec.js index 1f2825b97ad0..229574dd2be2 100644 --- a/packages/server/test/integration/http_requests_spec.js +++ b/packages/server/test/integration/http_requests_spec.js @@ -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, }, @@ -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 () { @@ -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') }) }) @@ -3961,7 +3983,7 @@ describe('Routes', () => { it('sets x-cypress-file-path headers', function () { return this.rp(`${this.proxy}/assets/app.css`) .then((res) => { - expect(res.headers).to.have.property('x-cypress-file-path', encodeURIComponent(`${Fixtures.projectPath('no-server')}/dev/assets/app.css`)) + expect(res.headers).to.have.property('x-cypress-file-path', `${Fixtures.projectPath('no-server')}/dev/assets/app.css`) }) }) diff --git a/packages/server/test/unit/config_spec.js b/packages/server/test/unit/config_spec.js index dbffd694aabf..ed61141ae684 100644 --- a/packages/server/test/unit/config_spec.js +++ b/packages/server/test/unit/config_spec.js @@ -369,8 +369,8 @@ describe('lib/config', () => { }) }) - it('passes if a string contains an invalid character but encodes it', function () { - this.setup({ fileServerFolder: encodeURIComponent('/specialCharacters/无法解析的特殊字符') }) + it('passes if a string contains encoded special characters', function () { + this.setup({ fileServerFolder: encodeURI('/specialCharacters/无法解析的特殊字符') }) return this.expectValidationPasses() }) diff --git "a/system-tests/projects/no-server/dev/_ :;.,\"'!(){}[]@<>=-+*$&`|~^\304\265\347\254\246/foo.txt" "b/system-tests/projects/no-server/dev/_ :;.,\"'!(){}[]@<>=-+*$&`|~^\304\265\347\254\246/foo.txt" new file mode 100644 index 000000000000..19102815663d --- /dev/null +++ "b/system-tests/projects/no-server/dev/_ :;.,\"'!(){}[]@<>=-+*$&`|~^\304\265\347\254\246/foo.txt" @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git "a/system-tests/projects/no-server/dev/_ :;.,\"'!(){}[]@<>=-+*$&`|~^\304\265\347\254\246/index.html" "b/system-tests/projects/no-server/dev/_ :;.,\"'!(){}[]@<>=-+*$&`|~^\304\265\347\254\246/index.html" new file mode 100644 index 000000000000..96fb9b796268 --- /dev/null +++ "b/system-tests/projects/no-server/dev/_ :;.,\"'!(){}[]@<>=-+*$&`|~^\304\265\347\254\246/index.html" @@ -0,0 +1,7 @@ + + + + + index.html content + + From 81d95bfaf398acdc4511932393f2fbf2b59bc0ca Mon Sep 17 00:00:00 2001 From: Matt Schile Date: Thu, 16 May 2024 16:57:35 -0600 Subject: [PATCH 11/11] Update cli/CHANGELOG.md --- cli/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 40a7864b407c..f249ebb59cdc 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -6,7 +6,7 @@ _Released 5/21/2024 (PENDING)_ **Bugfixes:** - 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 parsing the `fileServerFolder` path when there are special characters. Fixes [#25839](https://github.com/cypress-io/cypress/issues/25839). +- 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). **Dependency Updates:**