Skip to content

Commit 295e766

Browse files
committedFeb 11, 2021
lib: remove usage of url.parse
Since url.parse() is deprecated, it must not be used inside Node.js. PR-URL: #36853 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Beth Griggs <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]>
1 parent ad38be4 commit 295e766

File tree

6 files changed

+7
-99
lines changed

6 files changed

+7
-99
lines changed
 

‎doc/api/deprecations.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -2051,12 +2051,15 @@ expose values under these names.
20512051
### DEP0109: `http`, `https`, and `tls` support for invalid URLs
20522052
<!-- YAML
20532053
changes:
2054+
- version: REPLACEME
2055+
pr-url: https://github.com/nodejs/node/pull/36853
2056+
description: End-of-Life.
20542057
- version: v11.0.0
20552058
pr-url: https://github.com/nodejs/node/pull/20270
20562059
description: Runtime deprecation.
20572060
-->
20582061

2059-
Type: Runtime
2062+
Type: End-of-Life
20602063

20612064
Some previously supported (but strictly invalid) URLs were accepted through the
20622065
[`http.request()`][], [`http.get()`][], [`https.request()`][],

‎lib/_http_client.js

+1-17
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const {
4242
} = primordials;
4343

4444
const net = require('net');
45-
const url = require('url');
4645
const assert = require('internal/assert');
4746
const { once } = require('internal/util');
4847
const {
@@ -98,27 +97,12 @@ class HTTPClientAsyncResource {
9897
}
9998
}
10099

101-
let urlWarningEmitted = false;
102100
function ClientRequest(input, options, cb) {
103101
FunctionPrototypeCall(OutgoingMessage, this);
104102

105103
if (typeof input === 'string') {
106104
const urlStr = input;
107-
try {
108-
input = urlToHttpOptions(new URL(urlStr));
109-
} catch (err) {
110-
input = url.parse(urlStr);
111-
if (!input.hostname) {
112-
throw err;
113-
}
114-
if (!urlWarningEmitted && !process.noDeprecation) {
115-
urlWarningEmitted = true;
116-
process.emitWarning(
117-
`The provided URL ${urlStr} is not a valid URL, and is supported ` +
118-
'in the http module solely for compatibility.',
119-
'DeprecationWarning', 'DEP0109');
120-
}
121-
}
105+
input = urlToHttpOptions(new URL(urlStr));
122106
} else if (input && input[searchParamsSymbol] &&
123107
input[searchParamsSymbol][searchParamsSymbol]) {
124108
// url.URL instance

‎lib/https.js

+1-17
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const {
3737
require('internal/util').assertCrypto();
3838

3939
const tls = require('tls');
40-
const url = require('url');
4140
const { Agent: HttpAgent } = require('_http_agent');
4241
const {
4342
Server: HttpServer,
@@ -296,27 +295,12 @@ Agent.prototype._evictSession = function _evictSession(key) {
296295

297296
const globalAgent = new Agent();
298297

299-
let urlWarningEmitted = false;
300298
function request(...args) {
301299
let options = {};
302300

303301
if (typeof args[0] === 'string') {
304302
const urlStr = ArrayPrototypeShift(args);
305-
try {
306-
options = urlToHttpOptions(new URL(urlStr));
307-
} catch (err) {
308-
options = url.parse(urlStr);
309-
if (!options.hostname) {
310-
throw err;
311-
}
312-
if (!urlWarningEmitted && !process.noDeprecation) {
313-
urlWarningEmitted = true;
314-
process.emitWarning(
315-
`The provided URL ${urlStr} is not a valid URL, and is supported ` +
316-
'in the https module solely for compatibility.',
317-
'DeprecationWarning', 'DEP0109');
318-
}
319-
}
303+
options = urlToHttpOptions(new URL(urlStr));
320304
} else if (args[0] && args[0][searchParamsSymbol] &&
321305
args[0][searchParamsSymbol][searchParamsSymbol]) {
322306
// url.URL instance

‎lib/tls.js

+1-17
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const { isArrayBufferView } = require('internal/util/types');
5555

5656
const net = require('net');
5757
const { getOptionValue } = require('internal/options');
58-
const url = require('url');
5958
const { getRootCertificates, getSSLCiphers } = internalBinding('crypto');
6059
const { Buffer } = require('buffer');
6160
const EventEmitter = require('events');
@@ -230,7 +229,6 @@ function check(hostParts, pattern, wildcards) {
230229
return true;
231230
}
232231

233-
let urlWarningEmitted = false;
234232
exports.checkServerIdentity = function checkServerIdentity(hostname, cert) {
235233
const subject = cert.subject;
236234
const altNames = cert.subjectaltname;
@@ -246,21 +244,7 @@ exports.checkServerIdentity = function checkServerIdentity(hostname, cert) {
246244
if (StringPrototypeStartsWith(name, 'DNS:')) {
247245
ArrayPrototypePush(dnsNames, StringPrototypeSlice(name, 4));
248246
} else if (StringPrototypeStartsWith(name, 'URI:')) {
249-
let uri;
250-
try {
251-
uri = new URL(StringPrototypeSlice(name, 4));
252-
} catch {
253-
const slicedName = StringPrototypeSlice(name, 4);
254-
uri = url.parse(slicedName);
255-
if (!urlWarningEmitted && !process.noDeprecation) {
256-
urlWarningEmitted = true;
257-
process.emitWarning(
258-
`The URI ${slicedName} found in cert.subjectaltname ` +
259-
'is not a valid URI, and is supported in the tls module ' +
260-
'solely for compatibility.',
261-
'DeprecationWarning', 'DEP0109');
262-
}
263-
}
247+
const uri = new URL(StringPrototypeSlice(name, 4));
264248

265249
// TODO(bnoordhuis) Also use scheme.
266250
ArrayPrototypePush(uriNames, uri.hostname);

‎test/parallel/test-http-deprecated-urls.js

-33
This file was deleted.

‎test/parallel/test-tls-check-server-identity.js

-14
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ const util = require('util');
3030

3131
const tls = require('tls');
3232

33-
common.expectWarning('DeprecationWarning', [
34-
['The URI http://[a.b.a.com]/ found in cert.subjectaltname ' +
35-
'is not a valid URI, and is supported in the tls module ' +
36-
'solely for compatibility.',
37-
'DEP0109'],
38-
]);
39-
4033
const tests = [
4134
// False-y values.
4235
{
@@ -282,13 +275,6 @@ const tests = [
282275
error: 'Host: a.b.a.com. is not in the cert\'s altnames: ' +
283276
'URI:http://*.b.a.com/'
284277
},
285-
// Invalid URI
286-
{
287-
host: 'a.b.a.com', cert: {
288-
subjectaltname: 'URI:http://[a.b.a.com]/',
289-
subject: {}
290-
}
291-
},
292278
// IP addresses
293279
{
294280
host: 'a.b.a.com', cert: {

0 commit comments

Comments
 (0)
Please sign in to comment.