Skip to content

Commit 917d1d2

Browse files
authored
refactor: replace deprecated String.prototype.substr() (#646)
`.substr()` is deprecated so we replace it with `.slice()` which works similarily but isn't deprecated. See also: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr Signed-off-by: Lam Wei Li <peteriman@mail.com>
1 parent 020801a commit 917d1d2

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

lib/parser-v3/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function decodePacket (data, binaryType, utf8decode) {
137137
type = data.charAt(0);
138138

139139
if (type === 'b') {
140-
return decodeBase64Packet(data.substr(1), binaryType);
140+
return decodeBase64Packet(data.slice(1), binaryType);
141141
}
142142

143143
if (utf8decode) {
@@ -152,7 +152,7 @@ export function decodePacket (data, binaryType, utf8decode) {
152152
}
153153

154154
if (data.length > 1) {
155-
return { type: packetslist[type], data: data.substring(1) };
155+
return { type: packetslist[type], data: data.slice(1) };
156156
} else {
157157
return { type: packetslist[type] };
158158
}
@@ -191,7 +191,7 @@ function tryDecode(data) {
191191

192192
export function decodeBase64Packet (msg, binaryType) {
193193
var type = packetslist[msg.charAt(0)];
194-
var data = Buffer.from(msg.substr(1), 'base64');
194+
var data = Buffer.from(msg.slice(1), 'base64');
195195
if (binaryType === 'arraybuffer') {
196196
var abv = new Uint8Array(data.length);
197197
for (var i = 0; i < abv.length; i++){
@@ -305,7 +305,7 @@ export function decodePayload (data, binaryType, callback) {
305305
return callback(err, 0, 1);
306306
}
307307

308-
msg = data.substr(i + 1, n);
308+
msg = data.slice(i + 1, i + 1 + n);
309309

310310
if (length != msg.length) {
311311
// parser error - ignoring payload

lib/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ export class Server extends BaseServer {
555555
return;
556556
}
557557

558-
const head = Buffer.from(upgradeHead); // eslint-disable-line node/no-deprecated-api
558+
const head = Buffer.from(upgradeHead);
559559
upgradeHead = null;
560560

561561
// delegate to ws
@@ -643,7 +643,7 @@ export class Server extends BaseServer {
643643
path += "/";
644644

645645
function check(req) {
646-
return path === req.url.substr(0, path.length);
646+
return path === req.url.slice(0, path.length);
647647
}
648648

649649
// cache and clean up listeners

test/server.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ describe("server", () => {
181181
.get(`http://localhost:${port}/engine.io/`)
182182
.query({ transport: "polling", EIO: 4 })
183183
.end((err, res) => {
184-
const sid = JSON.parse(res.text.substring(1)).sid;
184+
const sid = JSON.parse(res.text.slice(1)).sid;
185185

186186
request
187187
.get(`http://localhost:${port}/engine.io/`)
@@ -3357,7 +3357,7 @@ describe("server", () => {
33573357
expect(res.headers["set-cookie"].length).to.be(2);
33583358
expect(res.headers["set-cookie"][1]).to.be("mycookie=456");
33593359

3360-
const sid = JSON.parse(res.text.substring(5)).sid;
3360+
const sid = JSON.parse(res.text.slice(5)).sid;
33613361

33623362
request
33633363
.post(`http://localhost:${port}/engine.io/`)
@@ -3394,7 +3394,7 @@ describe("server", () => {
33943394
expect(res.headers["set-cookie"].length).to.be(2);
33953395
expect(res.headers["set-cookie"][1]).to.be("mycookie=456");
33963396

3397-
const sid = JSON.parse(res.text.substring(5)).sid;
3397+
const sid = JSON.parse(res.text.slice(5)).sid;
33983398

33993399
request
34003400
.post(`http://localhost:${port}/engine.io/`)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy