Skip to content

Commit d964865

Browse files
authored
fix: update getPath to use WHATWG URL API (#28354)
1 parent 2041c69 commit d964865

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

cli/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ _Released 11/21/2023 (PENDING)_
1313
- Fixed an issue where dynamic intercept aliases now show with alias name instead of "no alias" in driver. Addresses [#24653](https://github.com/cypress-io/cypress/issues/24653)
1414
- Fixed an issue where [aliasing individual requests](https://docs.cypress.io/api/commands/intercept#Aliasing-individual-requests) with `cy.intercept()` led to an error when retrieving all of the aliases with `cy.get(@alias.all)` . Addresses [#25448](https://github.com/cypress-io/cypress/issues/25448)
1515
- The URL of the application under test and command error "Learn more" links now open externally instead of in the Cypress-launched browser. Fixes [#24572](https://github.com/cypress-io/cypress/issues/24572).
16+
- Fixed issue where some URLs would timeout in pre-request correlation. Addressed in [#28354](https://github.com/cypress-io/cypress/pull/28354).
1617

1718
**Misc:**
1819

packages/network/lib/uri.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ export function addDefaultPort (urlToCheck: any) {
8787
}
8888

8989
export function getPath (urlToCheck: string) {
90-
return url.parse(urlToCheck).path
90+
// since we are only concerned with the pathname and search properties,
91+
// we can set the base to a fake base to handle relative urls
92+
const url = new URL(urlToCheck, 'http://fake-base.com')
93+
94+
return `${url.pathname}${url.search}`
9195
}
9296

9397
const localhostIPRegex = /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/

packages/network/test/unit/uri_spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ import { URL } from 'url'
44
import { uri } from '../../lib'
55

66
describe('lib/uri', () => {
7+
context('.getPath', () => {
8+
it('returns the pathname and search', () => {
9+
expect(uri.getPath('http://localhost:9999/foo/bar?baz=quux#/index.html')).to.eq('/foo/bar?baz=quux')
10+
})
11+
12+
it('supports encoded characters', () => {
13+
expect(uri.getPath('http://localhost:9999?foo=0%3C1')).to.eq('/?foo=0%3C1')
14+
})
15+
16+
it('does not encode the "|" character', () => {
17+
expect(uri.getPath('http://localhost:9999?foo=bar|baz')).to.eq('/?foo=bar|baz')
18+
})
19+
20+
it('works with relative urls', () => {
21+
expect(uri.getPath('/foo/bar?foo=bar|baz')).to.eq('/foo/bar?foo=bar|baz')
22+
})
23+
})
24+
725
context('.isLocalhost', () => {
826
it('http://localhost is localhost', () => {
927
expect(uri.isLocalhost(new URL('http://localhost'))).to.be.true

0 commit comments

Comments
 (0)