diff --git a/packages/driver/cypress/integration/cypress/location_spec.js b/packages/driver/cypress/integration/cypress/location_spec.js index aa509354c73..558bf049eb5 100644 --- a/packages/driver/cypress/integration/cypress/location_spec.js +++ b/packages/driver/cypress/integration/cypress/location_spec.js @@ -426,5 +426,14 @@ describe('src/cypress/location', () => { expect(url).to.eq('http://localhost:3500/fixtures/sinon.html') }) + + // https://github.com/cypress-io/cypress/issues/5090 + it('handles query param with two dots', function () { + let url = this.normalize('?foo=..') + + url = Location.qualifyWithBaseUrl('http://localhost:3500/', url) + + expect(url).to.eq('http://localhost:3500/?foo=..') + }) }) }) diff --git a/packages/driver/src/cypress/location.js b/packages/driver/src/cypress/location.js index 783661935ec..77dd024ea9e 100644 --- a/packages/driver/src/cypress/location.js +++ b/packages/driver/src/cypress/location.js @@ -129,6 +129,12 @@ class $Location { } static isUrlLike (url) { + // https://github.com/cypress-io/cypress/issues/5090 + // In the case of a url like /?foo=.. + if (/\.{2,}/.test(url)) { + return false + } + // beta.cypress.io // aws.amazon.com/bucket/foo // foo.bar.co.uk @@ -139,18 +145,7 @@ class $Location { } static fullyQualifyUrl (url) { - if (this.isFullyQualifiedUrl(url)) { - return url - } - - const existing = new UrlParse(window.location.href) - - // always normalize against our existing origin - // as the baseUrl so that we do not accidentally - // have relative url's - url = new UrlParse(url, existing.origin) - - return url.toString() + return this.resolve(window.location.origin, url) } static mergeUrlWithParams (url, params) { @@ -228,24 +223,7 @@ class $Location { } static resolve (from, to) { - // if to is fully qualified then - // just return that - if (this.isFullyQualifiedUrl(to)) { - return to - } - - // else take from and figure out if - // to is relative or absolute-relative - - // if to is absolute relative '/foo' - if (this.isAbsoluteRelative(to)) { - // get origin from 'from' - const { origin } = this.create(from) - - return this.join(origin, to) - } - - return this.join(from, to) + return new URL(to, from).toString() } static create (remote) {