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

baseUrl slash breaks URL when trying to append query string #25554

Open
Noyabronok opened this issue Jan 24, 2023 · 3 comments
Open

baseUrl slash breaks URL when trying to append query string #25554

Noyabronok opened this issue Jan 24, 2023 · 3 comments
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

@Noyabronok
Copy link

Noyabronok commented Jan 24, 2023

Current behavior

baseUrl: https://..../xyz.html
cy.visit('?x=y')

Cypress tries to access http://.../xyz.html/?x=y

The extra slash after xyz.html breaks the request

Desired behavior

Do not add a slash at the end of the baseUrl if it's not needed, as in the case of query parameters

Test code to reproduce

NA

Cypress Version

12.3

Node version

14

Operating System

macOS 12.6.2

Debug Logs

No response

Other

Here's a temporary workaround for the problem that I came up with. Basically, explicitly providing the URL to the visit function, instead of relying on baseUrl, produces the desired behavior.

Cypress.Commands.overwrite(
  'visit',
  (originalFn, url: string, options: Partial<Cypress.VisitOptions>) => {
    options = options ?? {};
    // this is a workaround for a cypress bug that adds a / to the end of baseUrl which breaks the URL if it ends on .html
    // if you don't like this fix, there's another hack, which is to add some dummy query string to the baseUrl
    if (url?.startsWith('?')) {
      // terminal logging enabled by ELECTRON_ENABLE_LOGGING=1
      console.log('Setting baseUrl explicitly to remove unwanted /');
      options.qs = {
        ...options?.qs,
        ...Object.fromEntries(new URLSearchParams(url)),
      };
      url = Cypress.config().baseUrl;
    }

    return originalFn(url, options);
  }
);
@AtofStryker
Copy link
Contributor

Hi @Noyabronok. Thank you for opening an issue. I was able to reproduce this behavior and am going to route this to a team. The reproduction link is here.

@AtofStryker AtofStryker removed their assignment Jan 27, 2023
@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
@kgartland-rstudio
Copy link

I just hit this bug as well. Are there any updates?

I'm on Cypress 12.7.0

@AtofStryker
Copy link
Contributor

Hi @kgartland-rstudio. No updates as of yet. If this work does get picked up, we will be sure to update the issue.

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
Development

No branches or pull requests

4 participants