From 36ecac2dee61b81f1d48bfb99bd376d55f893144 Mon Sep 17 00:00:00 2001 From: Ayoub Mabrouk Date: Sat, 20 Dec 2025 20:20:53 +0100 Subject: [PATCH] refactor: replace deprecated substr() with slice() Replace all instances of String.prototype.substr() with String.prototype.slice() to use the standard, non-deprecated method. This maintains compatibility with Node.js >= 0.8.0 while following modern JavaScript best practices. All replacements maintain identical functionality as slice() and substr() behave the same for these use cases. --- index.js | 6 +++--- test/session.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index eb15ea64..3e23e901 100644 --- a/index.js +++ b/index.js @@ -593,7 +593,7 @@ function getcookie(req, name, secrets) { raw = cookies[name]; if (raw) { - if (raw.substr(0, 2) === 's:') { + if (raw.slice(0, 2) === 's:') { val = unsigncookie(raw.slice(2), secrets); if (val === false) { @@ -620,7 +620,7 @@ function getcookie(req, name, secrets) { raw = req.cookies[name]; if (raw) { - if (raw.substr(0, 2) === 's:') { + if (raw.slice(0, 2) === 's:') { val = unsigncookie(raw.slice(2), secrets); if (val) { @@ -696,7 +696,7 @@ function issecure(req, trustProxy) { var header = req.headers['x-forwarded-proto'] || ''; var index = header.indexOf(','); var proto = index !== -1 - ? header.substr(0, index).toLowerCase().trim() + ? header.slice(0, index).toLowerCase().trim() : header.toLowerCase().trim() return proto === 'https'; diff --git a/test/session.js b/test/session.js index abf846f5..405e3ddf 100644 --- a/test/session.js +++ b/test/session.js @@ -1299,7 +1299,7 @@ describe('session()', function(){ var store = new session.MemoryStore() var server = createServer({ resave: false, store: store }, function (req, res) { if (req.method === 'PUT') { - req.session.token = req.url.substr(1) + req.session.token = req.url.slice(1) } res.end('token=' + (req.session.token || '')) })