From 977038a046ad6226c354965a2c0cd40db0d88745 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Wed, 7 Aug 2024 14:20:22 -0400 Subject: [PATCH 1/2] empty commit From df2d4c0ba033ef3f4baf87f647c2d1335d66541a Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Mon, 9 Sep 2024 12:56:35 -0400 Subject: [PATCH 2/2] commit initial changes --- packages/server/lib/file_server.js | 8 +++++--- packages/server/lib/request.js | 2 +- packages/server/lib/server-base.ts | 6 +++--- packages/server/lib/util/ensure-url.ts | 5 ++--- packages/server/test/integration/http_requests_spec.js | 7 +++---- packages/server/test/unit/fixture_spec.js | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/server/lib/file_server.js b/packages/server/lib/file_server.js index ca5bcb5dd60f..6359492d6302 100644 --- a/packages/server/lib/file_server.js +++ b/packages/server/lib/file_server.js @@ -2,7 +2,6 @@ const _ = require('lodash') const debug = require('debug')('cypress:server:file_server') -const url = require('url') const http = require('http') const path = require('path') const send = require('send') @@ -27,16 +26,19 @@ const onRequest = function (req, res, expectedToken, fileServerFolder) { req.url, ]) + const fileServerUrl = new URL(path.join(...args)) + const reqUrl = new URL(req.url) + // strip off any query params from our req's url // since we're pulling this from the file system // it does not understand query params // and make sure we decode the uri which swaps out // %20 with white space - const file = decodeURI(url.parse(path.join(...args)).pathname) + const file = decodeURI(fileServerUrl.pathname) res.setHeader('x-cypress-file-path', encodeURI(file)) - return send(req, url.parse(req.url).pathname, { + return send(req, reqUrl.pathname, { root: path.resolve(fileServerFolder), }) .on('error', (err) => { diff --git a/packages/server/lib/request.js b/packages/server/lib/request.js index 4554740153ae..1e393458b4fd 100644 --- a/packages/server/lib/request.js +++ b/packages/server/lib/request.js @@ -551,7 +551,7 @@ module.exports = function (options = {}) { cookies = [cookies] } - const parsedUrl = url.parse(resUrl) + const parsedUrl = new URL(resUrl) const defaultDomain = parsedUrl.hostname debug('setting cookies on browser %o', { url: parsedUrl.href, defaultDomain, cookies }) diff --git a/packages/server/lib/server-base.ts b/packages/server/lib/server-base.ts index b9f6b78bf004..97ec65358044 100644 --- a/packages/server/lib/server-base.ts +++ b/packages/server/lib/server-base.ts @@ -605,7 +605,7 @@ export class ServerBase { // get the protocol using req.connection.encrypted // get the port & hostname from host header const fullUrl = `${req.connection.encrypted ? 'https' : 'http'}://${host}` - const { hostname, protocol } = url.parse(fullUrl) + const { hostname, protocol } = new URL(fullUrl) const { port } = cors.parseUrlIntoHostProtocolDomainTldPort(fullUrl) const onProxyErr = (err, req, res) => { @@ -766,9 +766,9 @@ export class ServerBase { // nuke any hashes from our url since // those those are client only and do // not apply to http requests - urlStr = url.parse(urlStr) + urlStr = new URL(urlStr) urlStr.hash = null - urlStr = urlStr.format() + urlStr = urlStr.href const originalUrl = urlStr diff --git a/packages/server/lib/util/ensure-url.ts b/packages/server/lib/util/ensure-url.ts index 5b644218b67f..e54f0c224642 100644 --- a/packages/server/lib/util/ensure-url.ts +++ b/packages/server/lib/util/ensure-url.ts @@ -2,7 +2,6 @@ import _ from 'lodash' import Bluebird from 'bluebird' import debugModule from 'debug' import rp from '@cypress/request-promise' -import * as url from 'url' import { agent, connect } from '@packages/network' const debug = debugModule('cypress:server:ensure-url') @@ -50,9 +49,9 @@ export const retryIsListening = (urlStr: string, options: RetryOptions) => { export const isListening = (urlStr: string) => { // takes a urlStr and verifies the hostname + port is listening - let { hostname, protocol, port } = url.parse(urlStr) + let { hostname, protocol, port } = new URL(urlStr) - if (port == null) { + if (port.length === 0) { port = protocol === 'https:' ? '443' : '80' } diff --git a/packages/server/test/integration/http_requests_spec.js b/packages/server/test/integration/http_requests_spec.js index 13eba9bf4ab2..93862084a5e1 100644 --- a/packages/server/test/integration/http_requests_spec.js +++ b/packages/server/test/integration/http_requests_spec.js @@ -7,7 +7,6 @@ const compression = require('compression') const dns = require('dns') const express = require('express') const http = require('http') -const url = require('url') let zlib = require('zlib') const str = require('underscore.string') const evilDns = require('evil-dns') @@ -4416,15 +4415,15 @@ describe('Routes', () => { Fixtures.scaffoldProject('e2e') .then(() => { this.httpSrv = http.createServer((req, res) => { - const { query } = url.parse(req.url, true) + const { search } = new URL(req.url, true) - if (_.has(query, 'chunked')) { + if (_.has(search, 'chunked')) { res.setHeader('tranfer-encoding', 'chunked') } else { res.setHeader('content-length', '0') } - res.writeHead(Number(query.status), { + res.writeHead(Number(search.status), { 'x-foo': 'bar', }) diff --git a/packages/server/test/unit/fixture_spec.js b/packages/server/test/unit/fixture_spec.js index ddcd9dee73b9..776b73295e95 100644 --- a/packages/server/test/unit/fixture_spec.js +++ b/packages/server/test/unit/fixture_spec.js @@ -32,7 +32,7 @@ describe('lib/fixture', () => { }) context('file not found', () => { - it('throws when file cannot be found', function () { + it('throws when file cannot be found', async function () { const p = 'does-not-exist.json' return fixture.get(this.fixturesFolder, p)