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

[ERR_INVALID_CHAR]: Invalid character in header content ["x-cypress-file-path"] #25839

Open
Nutcracker52 opened this issue Feb 16, 2023 · 9 comments · May be fixed by #29162
Open

[ERR_INVALID_CHAR]: Invalid character in header content ["x-cypress-file-path"] #25839

Nutcracker52 opened this issue Feb 16, 2023 · 9 comments · May be fixed by #29162
Labels
E2E Issue related to end-to-end testing Reproducible Can be reproduced Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: bug

Comments

@Nutcracker52
Copy link

Nutcracker52 commented Feb 16, 2023

Current behavior

#25273 related to this closed issue and I can confirm this is happening and it's pretty annyoing.

Error Code pops

TypeError [ERR_INVALID_CHAR] [ERR_INVALID_CHAR]: Invalid character in header content ["x-cypress-file-path"]
    at ServerResponse.setHeader (_http_outgoing.js:561:3)
    at onRequest (C:\Users\Nutcracker52\AppData\Local\Cypress\Cache\8.3.1\Cypress\resources\app\packages\server\lib\file_server.js:37:7)
    at Server.<anonymous> (C:\Users\Nutcracker52\AppData\Local\Cypress\Cache\8.3.1\Cypress\resources\app\packages\server\lib\file_server.js:57:16)
    at Server.emit (events.js:315:20)
    at parserOnIncoming (_http_server.js:874:12)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17)

test I am trying to run

  it('validation email sent and user can confirm', () => {
    cy.getEmail(Cypress.env('emailAddress'), 'Welcome to ABC', true).then(email => {
      expect(email.subject).equal('Welcome to ABC')
      const validateUrl = getEmailLink(email.html, `${Cypress.env('appUrl')}/account/verify?code`, '"')
      cy.visit(validateUrl)
      cy.contains('you are now ready to login!', { timeout: 30000 })
    })
  })

I am reading emails from an API and check that email has been received and then email contains a link and click that link

Desired behavior

Cypress shouldn't throw any errors while test is running. This completely crashes Cypress and I have to run tests again.

To avoid the error I had to add cy.visit command as first line to the code. which is not necessary.

Test code to reproduce

please use the given code above.
get email is a function that we designed to get emails from an api.
I cannot share it.

Cypress Version

8.3.1

Node version

16.19.0

Operating System

Windows 11

Debug Logs

No response

Other

No response

@flotwig
Copy link
Contributor

flotwig commented Feb 22, 2023

@Nutcracker52 what is the value of validateUrl when this error occurs? I'm guessing it contains some special characters that we aren't handling correctly in the internal HTTP file server.

@flotwig flotwig assigned mjhenkes and unassigned flotwig Feb 28, 2023
@umajho
Copy link

umajho commented Mar 12, 2023

@Nutcracker52 what is the value of validateUrl when this error occurs? I'm guessing it contains some special characters that we aren't handling correctly in the internal HTTP file server.

I can confirm at least special characters in paths can cause this problem.
I cloned easy-markdown-editor in a folder, which has an ancestor folder called Umaĵo, and this error occurred when I tried run its tests. after renaming the folder from Umaĵo to Umajho, that error goes away.

(OS: macOS 12.6.3; cypress version: 10.11.0)

@mjhenkes
Copy link
Member

@umajho, I attempted a recreation here: https://github.com/mjhenkes/issue-25839 but i think my one test is too simplistic.

Which tests do you see failing in easy-markdown-editor?

@mjhenkes mjhenkes assigned AtofStryker and unassigned mjhenkes Mar 14, 2023
@umajho
Copy link

umajho commented Mar 15, 2023

Cypress just exited while running the first test it picked.

sh-3.2$ mkdir Umaĵo
sh-3.2$ cd Umaĵo/
sh-3.2$ git clone https://github.com/Ionaru/easy-markdown-editor
Cloning into 'easy-markdown-editor'...
remote: Enumerating objects: 6994, done.
remote: Counting objects: 100% (1074/1074), done.
remote: Compressing objects: 100% (410/410), done.
remote: Total 6994 (delta 718), reused 970 (delta 649), pack-reused 5920
Receiving objects: 100% (6994/6994), 12.56 MiB | 1.92 MiB/s, done.
Resolving deltas: 100% (3073/3073), done.
sh-3.2$ cd easy-markdown-editor/
sh-3.2$ pnpm i
 WARN  deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
 WARN  deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
 WARN  deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
 WARN  deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
 WARN  deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
 WARN  deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
 WARN  deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
Packages: +732
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packages are hard linked from the content-addressable store to the virtual store.
  Content-addressable store is at: /Users/xxx/Library/pnpm/store/v3
  Virtual store is at:             node_modules/.pnpm
Progress: resolved 730, reused 730, downloaded 0, added 732, done

> easymde@2.18.0 prepare /private/tmp/Umaĵo/easy-markdown-editor
> gulp

[14:43:28] Using gulpfile /private/tmp/Umaĵo/easy-markdown-editor/gulpfile.js
[14:43:28] Starting 'default'...
[14:43:28] Starting 'styles'...
[14:43:28] Starting 'lint'...
[14:43:28] Finished 'lint' after 485 ms
[14:43:28] Starting 'scripts'...
[14:43:29] Finished 'styles' after 548 ms
[14:43:31] Finished 'scripts' after 2.84 s
[14:43:31] Finished 'default' after 3.33 s

dependencies:
+ @types/codemirror 5.60.7
+ @types/marked 4.0.8
+ codemirror 5.65.12 (6.0.1 is available)
+ codemirror-spell-checker 1.1.2
+ marked 4.2.12

devDependencies:
+ browserify 17.0.0
+ cypress 10.11.0 (12.8.0 is available)
+ eslint 8.36.0
+ eslint-plugin-cypress 2.12.1
+ gulp 4.0.2
+ gulp-clean-css 4.3.0
+ gulp-concat 2.6.1
+ gulp-eslint 6.0.0
+ gulp-header 2.0.9
+ gulp-rename 2.0.0
+ gulp-terser 2.1.0
+ gulp-uglify 3.0.2
+ typescript 4.9.5
+ vinyl-buffer 1.0.1
+ vinyl-source-stream 2.0.0

Done in 23.7s          
sh-3.2$ pnpm run cypress:run

> easymde@2.18.0 cypress:run /private/tmp/Umaĵo/easy-markdown-editor
> cypress run

Couldn't find tsconfig.json. tsconfig-paths will be skipped

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        10.11.0                                                                        │
  │ Browser:        Electron 106 (headless)                                                        │
  │ Node Version:   v19.7.0 (/usr/local/Cellar/node/19.7.0/bin/node)                               │
  │ Specs:          5 found (2-url-prompt/url-prompt.cy.js, 1-default-editor/preview.cy.js, 1-defa │
  │                 ult-editor/statusbar.cy.js, 1-default-editor/visual.cy.js, 3-class-prefix/clas │
  │                 s-prefix.cy.js)                                                                │
  │ Searched:       cypress/e2e/**/*.cy.{js,jsx,ts,tsx}                                            │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running:  2-url-prompt/url-prompt.cy.js                                                   (1 of 5)


  URL prompts
Invalid character in header content ["x-cypress-file-path"]
TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["x-cypress-file-path"]
    at ServerResponse.setHeader (node:_http_outgoing:579:3)
    at onRequest (/Users/xxx/Library/Caches/Cypress/10.11.0/Cypress.app/Contents/Resources/app/packages/server/lib/file_server.js:37:7)
    at Server.<anonymous> (/Users/xxx/Library/Caches/Cypress/10.11.0/Cypress.app/Contents/Resources/app/packages/server/lib/file_server.js:57:16)
    at Server.emit (node:events:527:28)
    at Server.emit (node:domain:475:12)
    at parserOnIncoming (node:_http_server:956:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)

 ELIFECYCLE  Command failed with exit code 1.
sh-3.2$ 

another try:

sh-3.2$ pnpm run cypress:run

> easymde@2.18.0 cypress:run /private/tmp/Umaĵo/easy-markdown-editor
> cypress run

Couldn't find tsconfig.json. tsconfig-paths will be skipped

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        10.11.0                                                                        │
  │ Browser:        Electron 106 (headless)                                                        │
  │ Node Version:   v19.7.0 (/usr/local/Cellar/node/19.7.0/bin/node)                               │
  │ Specs:          5 found (1-default-editor/preview.cy.js, 1-default-editor/statusbar.cy.js, 1-d │
  │                 efault-editor/visual.cy.js, 2-url-prompt/url-prompt.cy.js, 3-class-prefix/clas │
  │                 s-prefix.cy.js)                                                                │
  │ Searched:       cypress/e2e/**/*.cy.{js,jsx,ts,tsx}                                            │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running:  1-default-editor/preview.cy.js                                                  (1 of 5)


  Preview
Invalid character in header content ["x-cypress-file-path"]
TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["x-cypress-file-path"]
    at ServerResponse.setHeader (node:_http_outgoing:579:3)
    at onRequest (/Users/xxx/Library/Caches/Cypress/10.11.0/Cypress.app/Contents/Resources/app/packages/server/lib/file_server.js:37:7)
    at Server.<anonymous> (/Users/xxx/Library/Caches/Cypress/10.11.0/Cypress.app/Contents/Resources/app/packages/server/lib/file_server.js:57:16)
    at Server.emit (node:events:527:28)
    at Server.emit (node:domain:475:12)
    at parserOnIncoming (node:_http_server:956:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)

 ELIFECYCLE  Command failed with exit code 1.
sh-3.2$ 

Updating cypress to the latest version doesn't work as well:

sh-3.2$ pnpm up cypress --latest
 WARN  deprecated chokidar@2.1.8: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
 WARN  deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
 WARN  deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
 WARN  deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
 WARN  deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
 WARN  deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
 WARN  deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2.
Packages: +1 -1
+-
Progress: resolved 730, reused 730, downloaded 0, added 1, done

devDependencies:
- cypress 10.11.0
+ cypress 12.8.0

Done in 7.5s
sh-3.2$ pnpm run cypress:run

> easymde@2.18.0 cypress:run /private/tmp/Umaĵo/easy-markdown-editor
> cypress run

It looks like this is your first time using Cypress: 12.8.0

✔  Verified Cypress! /Users/xxx/Library/Caches/Cypress/12.8.0/Cypress.app

Opening Cypress...
Couldn't find tsconfig.json. tsconfig-paths will be skipped

====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        12.8.0                                                                         │
  │ Browser:        Electron 106 (headless)                                                        │
  │ Node Version:   v19.7.0 (/usr/local/Cellar/node/19.7.0/bin/node)                               │
  │ Specs:          5 found (1-default-editor/preview.cy.js, 1-default-editor/statusbar.cy.js, 1-d │
  │                 efault-editor/visual.cy.js, 2-url-prompt/url-prompt.cy.js, 3-class-prefix/clas │
  │                 s-prefix.cy.js)                                                                │
  │ Searched:       cypress/e2e/**/*.cy.{js,jsx,ts,tsx}                                            │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running:  1-default-editor/preview.cy.js                                                  (1 of 5)


  Preview
Invalid character in header content ["x-cypress-file-path"]
TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["x-cypress-file-path"]
    at ServerResponse.setHeader (node:_http_outgoing:579:3)
    at g (<embedded>:4721:1236)
    at Server.<anonymous> (<embedded>:4721:1875)
    at Server.emit (node:events:527:28)
    at parserOnIncoming (node:_http_server:956:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
 ELIFECYCLE  Command failed with exit code 1.
sh-3.2$ 

@AtofStryker
Copy link
Contributor

I'm hoping to give @mjhenkes 's repro a shot hopefully next week trying to run these tests with a different language configured in a ubuntu VM, or a special character in a folder name being used.

@AtofStryker
Copy link
Contributor

@mjhenkes I wasn't able to reproduce with your reprod but I was able to reproduce with easy-markdown-editor inside an ubuntu VM with the directory with a special character. I could not reproduce without the special character in the directory. I am going to go ahead and route this since we can reproduce the issue

Image

Image

@AtofStryker AtofStryker removed their assignment Mar 23, 2023
@Sitronik
Copy link

I had the same error, it turned out I forgot to initialize the environment variables on the command line that are used in cypress.config.ts

@nagash77 nagash77 added E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. and removed routed-to-e2e labels Apr 19, 2023
@minsoo-web
Copy link

I had the same error

In my case, it happened in the process of loading the local html file.

I didn't understand exactly why,
I found out that the src path of the img tag was caused by getting it from the assets folder, and the image file was named Korean.

The test could be executed normally by solving as follows.

Before

<img
  src="./assets/image/coffee/제주_비저링_콜드_브루.jpeg"
  width="200"
  height="200"
/>

After

<img
  src="./assets/image/coffee/coffee1.jpeg"
  width="200"
  height="200"
/>
image image

You can check this PR hamsurang/functional-coding-nutshell#12

@andrew-hurskiy
Copy link

If somebody still faces such issue, solution might be to encode url, before giving it to Cypress.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing Reproducible Can be reproduced Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. type: bug
Projects
None yet
9 participants