Skip to content

fix(webpack-dev-server): do not encodeUri in loader #20575

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

Merged
merged 7 commits into from
Mar 15, 2022
Merged

Conversation

lmiller1990
Copy link
Contributor

@lmiller1990 lmiller1990 commented Mar 11, 2022

User facing changelog

Correctly load specs with [ and ] characters when using @cypress/webpack-dev-server.

Additional details

Not really relevant to people outside Cypress, but when you back merge this to 10.0-release, you can use this branch for an example (same changes but updated system-tests project: https://github.com/cypress-io/cypress/compare/10.0-release...lmiller1990/20573?expand=1).

How has the user experience changed?

N/A

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • Have API changes been updated in the type definitions?
  • Have new configuration options been added to the cypress.schema.json?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 11, 2022

Thanks for taking the time to open a PR!

@cypress
Copy link

cypress bot commented Mar 11, 2022



Test summary

19334 0 218 0Flakiness 1


Run details

Project cypress
Status Passed
Commit 9398a96
Started Mar 15, 2022 1:21 AM
Ended Mar 15, 2022 1:33 AM
Duration 11:30 💡
OS Linux Debian - 10.10
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

cypress/integration/cypress/proxy-logging_spec.ts Flakiness
1 Proxy Logging > request logging > xhr log has response body/status code

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

import systemTests from '../lib/system-tests'

describe('@cypress/webpack-dev-server', function () {
systemTests.setup()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The start of the desperately needed system tests for WDS.

@@ -18,7 +18,7 @@ const makeImport = (file: Cypress.Cypress['spec'], filename: string, chunkName:
const magicComments = chunkName ? `/* webpackChunkName: "${chunkName}" */` : ''

return `"${filename}": {
shouldLoad: () => document.location.pathname.includes("${encodeURI(file.absolute)}"),
Copy link
Contributor Author

@lmiller1990 lmiller1990 Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't need this. If it passes CI, I'm pretty confident we are good to go. runner-ct as well as many projects in npm/react/examples exercise this code path.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test case for a spec with a file name with a space or unicode.

@lmiller1990 lmiller1990 marked this pull request as ready for review March 11, 2022 07:53
Copy link
Contributor

@JessicaSachs JessicaSachs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can get away with removing encodeURI to escape filenames. Can you try adding tests for unicode characters and file names with spaces in them?

@@ -18,7 +18,7 @@ const makeImport = (file: Cypress.Cypress['spec'], filename: string, chunkName:
const magicComments = chunkName ? `/* webpackChunkName: "${chunkName}" */` : ''

return `"${filename}": {
shouldLoad: () => document.location.pathname.includes("${encodeURI(file.absolute)}"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test case for a spec with a file name with a space or unicode.

@emilyrohrbough
Copy link
Member

@lmiller1990 Does this close #5426 as well?

@ZachJW34
Copy link
Contributor

@emilyrohrbough This is a CT specific change, so no this shouldn't fix the issue coming from e2e tests.

Copy link
Contributor

@ZachJW34 ZachJW34 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lmiller1990 @JessicaSachs tested this with a filename with a space and confirmed it does not work. [] are valid in some URLs. We can change the shouldLoad to something like

// Uses the browser URL parsing method, so if it does change per browser we would still match
shouldLoad: () => document.location.pathname.includes("${new URL(`http://localhost${file.absolute}`).pathname}")

// alternative: see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI#encoding_for_ipv6
function fixedEncodeURI(str) {
    return encodeURI(str).replace(/%5B/g, '[').replace(/%5D/g, ']');
}
shouldLoad: () => document.location.pathname.includes("${fixedEncodeURI(file.absolute)}"),

Test cases covering both brackets and encoded characters would be great.

@JessicaSachs
Copy link
Contributor

Why wouldn't we just decodeURI at the other end of whatever is consuming this?

@ZachJW34
Copy link
Contributor

ZachJW34 commented Mar 11, 2022

@JessicaSachs We consume it in the same line, so we could do

shouldLoad: () => decodeUri(document.location.pathname).includes(file.absolute)

Haven't tested it but should work.

@ZachJW34
Copy link
Contributor

@lmiller1990 created a PR targeting your branch that use decodeURI that will support both escaped characters and []
#20593

@lmiller1990 lmiller1990 requested a review from a team as a code owner March 14, 2022 02:28
@@ -39,7 +39,7 @@ export const iframesController = {
// attach header data for webservers
// to properly intercept and serve assets from the correct src root
// TODO: define a contract for dev-server plugins to configure this behavior
req.headers.__cypress_spec_path = req.params[0]
req.headers.__cypress_spec_path = encodeURI(req.params[0])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed this guy, too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, when we request a spec from the AUT it goes through this controller on the way to webpack-dev-server.

@lmiller1990
Copy link
Contributor Author

@JessicaSachs @ZachJW34 This is ready to go, it has tests for all the suggested edge cases (unicode, spaces, dots, square brackets). We needed to add this line on the server: https://github.com/cypress-io/cypress/pull/20575/files#diff-f41297d10b0dfd5080e119a99dbb460a6ac6defccb4cf402b189c2e1e3b96947R42.

I am not sure how this works with 10.0-release, we will find out when we rebase. The tests should help.

Copy link
Contributor

@ZachJW34 ZachJW34 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have similar tests for the vite-dev-server. I think it was confirmed that it's working but would be nice to have the same coverage across both dev-servers. Not relevant for this PR though!

@ZachJW34 ZachJW34 requested a review from JessicaSachs March 14, 2022 14:51
@JessicaSachs
Copy link
Contributor

We should have similar tests for the vite-dev-server. I think it was confirmed that it's working but would be nice to have the same coverage across both dev-servers. Not relevant for this PR though!

Agreed

Copy link
Contributor

@JessicaSachs JessicaSachs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding all of those tests @lmiller1990

@lmiller1990
Copy link
Contributor Author

Two approvals - going to update with latest master, then merge.

@lmiller1990 lmiller1990 merged commit 1b152fc into master Mar 15, 2022
@lmiller1990 lmiller1990 deleted the issue-20573 branch March 15, 2022 02:49
mike-plummer added a commit that referenced this pull request Dec 28, 2022
* Fix regression in path handling that had been previously fixed and lost in #20575
* Improve existing system test to cover this scenario
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants