From 48265dd60fcbb01a04d8fc55d7f8652122c66f3d Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Thu, 21 Feb 2019 23:50:50 +0000 Subject: [PATCH] Issue 3540: Fix baseUrl slash (#3546) closes #3540 and #3545 Tests: ```js /// it('test url', function () { cy.visit('/') var baseUrl = Cypress.config('baseUrl') //baseUrl = baseUrl + '/' // bug in Cypress - add slash cy.url().should('eq', Cypress.env('test_url')) cy.url().should('eq', baseUrl) }) it('test url - copy paste from @jennifer-shehane', function () { cy.visit('/') cy.url().should('eq', Cypress.config('baseUrl')) }) ``` ![obraz](https://user-images.githubusercontent.com/905878/53121397-10f83780-354c-11e9-8495-2474ced106e6.png) --- packages/server/lib/config.coffee | 6 +++-- packages/server/test/unit/config_spec.coffee | 27 +++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/server/lib/config.coffee b/packages/server/lib/config.coffee index e46ef822b4..6722e424f9 100644 --- a/packages/server/lib/config.coffee +++ b/packages/server/lib/config.coffee @@ -230,8 +230,10 @@ module.exports = { .value() if url = config.baseUrl - ## always strip trailing slashes - config.baseUrl = _.trimEnd(url, "/") + ## replace multiple slashes at the end of string to single slash + ## so http://localhost/// will be http://localhost/ + ## https://regexr.com/48rvt + config.baseUrl = url.replace(/\/\/+$/, "/") _.defaults(config, defaults) diff --git a/packages/server/test/unit/config_spec.coffee b/packages/server/test/unit/config_spec.coffee index 8bae88b78b..4922f6391f 100644 --- a/packages/server/test/unit/config_spec.coffee +++ b/packages/server/test/unit/config_spec.coffee @@ -509,9 +509,34 @@ describe "lib/config", -> it "namespace=__cypress", -> @defaults "namespace", "__cypress" + it "baseUrl=http://localhost:8000/app/", -> + @defaults "baseUrl", "http://localhost:8000/app/", { + baseUrl: "http://localhost:8000/app///" + } + + it "baseUrl=http://localhost:8000/app/", -> + @defaults "baseUrl", "http://localhost:8000/app/", { + baseUrl: "http://localhost:8000/app//" + } + it "baseUrl=http://localhost:8000/app", -> @defaults "baseUrl", "http://localhost:8000/app", { - baseUrl: "http://localhost:8000/app//" + baseUrl: "http://localhost:8000/app" + } + + it "baseUrl=http://localhost:8000/", -> + @defaults "baseUrl", "http://localhost:8000/", { + baseUrl: "http://localhost:8000//" + } + + it "baseUrl=http://localhost:8000/", -> + @defaults "baseUrl", "http://localhost:8000/", { + baseUrl: "http://localhost:8000/" + } + + it "baseUrl=http://localhost:8000", -> + @defaults "baseUrl", "http://localhost:8000", { + baseUrl: "http://localhost:8000" } it "javascripts=[]", ->