Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace deprecated String.prototype.substr() #646

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/parser-v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export function decodePacket (data, binaryType, utf8decode) {
type = data.charAt(0);

if (type === 'b') {
return decodeBase64Packet(data.substr(1), binaryType);
return decodeBase64Packet(data.slice(1), binaryType);
}

if (utf8decode) {
Expand All @@ -152,7 +152,7 @@ export function decodePacket (data, binaryType, utf8decode) {
}

if (data.length > 1) {
return { type: packetslist[type], data: data.substring(1) };
return { type: packetslist[type], data: data.slice(1) };
} else {
return { type: packetslist[type] };
}
Expand Down Expand Up @@ -191,7 +191,7 @@ function tryDecode(data) {

export function decodeBase64Packet (msg, binaryType) {
var type = packetslist[msg.charAt(0)];
var data = Buffer.from(msg.substr(1), 'base64');
var data = Buffer.from(msg.slice(1), 'base64');
if (binaryType === 'arraybuffer') {
var abv = new Uint8Array(data.length);
for (var i = 0; i < abv.length; i++){
Expand Down Expand Up @@ -305,7 +305,7 @@ export function decodePayload (data, binaryType, callback) {
return callback(err, 0, 1);
}

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

if (length != msg.length) {
// parser error - ignoring payload
Expand Down
4 changes: 2 additions & 2 deletions lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ export class Server extends BaseServer {
return;
}

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

// delegate to ws
Expand Down Expand Up @@ -643,7 +643,7 @@ export class Server extends BaseServer {
path += "/";

function check(req) {
return path === req.url.substr(0, path.length);
return path === req.url.slice(0, path.length);
}

// cache and clean up listeners
Expand Down
6 changes: 3 additions & 3 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ describe("server", () => {
.get(`http://localhost:${port}/engine.io/`)
.query({ transport: "polling", EIO: 4 })
.end((err, res) => {
const sid = JSON.parse(res.text.substring(1)).sid;
const sid = JSON.parse(res.text.slice(1)).sid;

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

const sid = JSON.parse(res.text.substring(5)).sid;
const sid = JSON.parse(res.text.slice(5)).sid;

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

const sid = JSON.parse(res.text.substring(5)).sid;
const sid = JSON.parse(res.text.slice(5)).sid;

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