-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
cy.request() errors when URL's path contains ’ character #5274
Comments
The root of the problem here is that you can't put a Unicode character in the HTTP request path or in the HTTP request headers. So the request that is made by: cy.request('http://google.com/’') Looks like this:
Which is invalid, since it contains Unicode, and shouldn't be sent anyways.
cy.request('http://google.com/%E2%80%99') Can we automatically do this for users somehow, without breaking existing behavior? Maybe by first running |
I am currently facing this same error as i am trying to verify through 1000s of links for places and many contains ' character. Any work around would be appreciated |
@ayandebbarman The issue is that Cypress does not encode the URL for you. You can use cy.visit('http://google.com/’') Do this: cy.visit(encodeURI('http://google.com/’')) |
I'm facing the same issue. If no one already started working on this issue I would gladly submit a PR to fix it. |
@avallete Feel free to open a PR, let us know if you have any questions we can help with. |
Use encodeURI inside `cy.request` to make sure the url does not contain any unescaped Unicode character. Fixes cypress-io#5274
Use `URL constructor` inside `cy.request` to make sure the url is well encoded when for both domain and pathname. Fixes cypress-io#5274
* test(pkg/driver): url with unicode characters into .request command * fix(pkg/driver): unicode character escaping in url for .request command Use encodeURI inside `cy.request` to make sure the url does not contain any unescaped Unicode character. Fixes #5274 * fix(pkg/driver): unicode character escaping in url for .request command Use `URL constructor` inside `cy.request` to make sure the url is well encoded when for both domain and pathname. Fixes #5274 * fix(tests): add some more tests for the case of a % character in url * refactor(tests): Move the tests to request_spec test file - Move the tests inside the request_spec test file instead of his own test file to be sure it will be maintain. - Rename some "it" test titles to semantically fit in the actual tests naming convention. - Remove the no more used 5274_spec.coffee test file.
The code for this is done in cypress-io/cypress#5813, but has yet to be released. |
Released in |
Current behavior:
Using a
’
character in the Path of the URL passed tocy.request()
causes aTypeError: The header content contains invalid characters
.The apostrophe is not a
'
apostrophe character, it's the’
character. If I paste the same url into my Chrome browser - the url redirects correctly.I tried a lot of other characters that did not cause any issue including some emojis 😅
Why is someone even doing this? Well @oak-wildwood was dynamically pulling content from our docs to generate urls then using
cy.request()
to visit them - so the generated URLs had the’
character.Stack trace
Desired behavior:
Requesting this url should not throw an
invalid characters
warning and should instead behave as Chrome does.Steps to reproduce: (app code and test code)
Versions
Cypress 3.4.1 & 3.5.0 prerelease
The text was updated successfully, but these errors were encountered: