Skip to content

Commit 8c7b87f

Browse files
committed
Remove calls to deprecated url.parse
1 parent 9d22796 commit 8c7b87f

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

benchmarks/FB/hello.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ function sequelizeQuery(callback) {
6161
}
6262

6363
function handlePrepared(req, res) {
64-
const values = url.parse(req.url, true);
65-
const queries = values.query.queries || 1;
64+
const values = new url.URL(req.url);
65+
const queries = values.searchParams.get('queries') || 1;
6666
const results = [];
6767
for (let i = 0; i < queries; ++i) {
6868
mysql2conn.execute(

benchmarks/http-select-and-render.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const port = process.env.PORT;
1010

1111
http
1212
.createServer((req, res) => {
13-
const q = url.parse(req.url, true);
13+
const q = new url.URL(req.url);
1414
if (q.pathname === '/render') {
15-
const sql = q.query.q;
16-
const n = q.query.n;
15+
const sql = q.searchParams.get('q');
16+
const n = q.searchParams.get('n');
1717
let rowsTotal = [];
1818
const doQueries = function(number) {
1919
if (number === 0) {

lib/connection_config.js

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const urlParse = require('url').parse;
3+
const { URL } = require('url');
44
const ClientConstants = require('./constants/client');
55
const Charsets = require('./constants/charsets');
66
let SSLProfiles = null;
@@ -232,29 +232,23 @@ class ConnectionConfig {
232232
}
233233

234234
static parseUrl(url) {
235-
url = urlParse(url, true);
235+
const parsedUrl = new URL(url);
236236
const options = {
237-
host: url.hostname,
238-
port: url.port,
239-
database: url.pathname.substr(1)
237+
host: parsedUrl.hostname,
238+
port: parsedUrl.port,
239+
database: parsedUrl.pathname.substr(1),
240+
user: parsedUrl.username,
241+
password: parsedUrl.password
240242
};
241-
if (url.auth) {
242-
const auth = url.auth.split(':');
243-
options.user = auth[0];
244-
options.password = auth[1];
245-
}
246-
if (url.query) {
247-
for (const key in url.query) {
248-
const value = url.query[key];
249-
try {
250-
// Try to parse this as a JSON expression first
251-
options[key] = JSON.parse(value);
252-
} catch (err) {
253-
// Otherwise assume it is a plain string
254-
options[key] = value;
255-
}
243+
parsedUrl.searchParams.forEach((value, key) => {
244+
try {
245+
// Try to parse this as a JSON expression first
246+
options[key] = JSON.parse(value);
247+
} catch (err) {
248+
// Otherwise assume it is a plain string
249+
options[key] = value;
256250
}
257-
}
251+
});
258252
return options;
259253
}
260254
}

0 commit comments

Comments
 (0)