GeezerVison is showing github.com — http: don't throw in isValidConnectPath · nodejs/node@7cb68d6
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/_http_client.js +10-15Lines changed: 10 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -60,7 +60,7 @@ const { |
60 | 60 | const Agent = require('_http_agent'); |
61 | 61 | const { Buffer } = require('buffer'); |
62 | 62 | const { defaultTriggerAsyncIdScope } = require('internal/async_hooks'); |
63 | | -const { URL, urlToHttpOptions, isURL } = require('internal/url'); |
| 63 | +const { URL, URLParse, urlToHttpOptions, isURL } = require('internal/url'); |
64 | 64 | const { |
65 | 65 | kOutHeaders, |
66 | 66 | kNeedDrain, |
@@ -196,23 +196,18 @@ function authoritiesMatch(canonicalHost, hostFromHeader) { |
196 | 196 |
|
197 | 197 | function isValidConnectPath(path) { |
198 | 198 | const match = CONNECT_PATH_REGEX.exec(path); |
199 | | - if (match === null) { |
| 199 | + if (match === null || +match[2] === 0) { |
200 | 200 | return false; |
201 | 201 | } |
202 | 202 |
|
203 | | - try { |
204 | | - validatePort(match[2], 'options.path', false); |
205 | | - const url = new URL(`http://${path}`); |
206 | | - |
207 | | - return url.hostname !== '' && |
208 | | - url.username === '' && |
209 | | - url.password === '' && |
210 | | - url.pathname === '/' && |
211 | | - url.search === '' && |
212 | | - url.hash === ''; |
213 | | - } catch { |
214 | | - return false; |
215 | | - } |
| 203 | + const url = URLParse(`http://${path}`); |
| 204 | + return url !== null && |
| 205 | + url.hostname !== '' && |
| 206 | + url.username === '' && |
| 207 | + url.password === '' && |
| 208 | + url.pathname === '/' && |
| 209 | + url.search === '' && |
| 210 | + url.hash === ''; |
216 | 211 | } |
217 | 212 |
|
218 | 213 | // https://datatracker.ietf.org/doc/html/rfc9112#section-3.2 |
|