refactor: replace deprecated substr() with slice() (#1099)

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.

Co-authored-by: bjohansebas <[email protected]>
This commit is contained in:
Ayoub Mabrouk
2026-07-05 21:30:48 -05:00
committed by GitHub
co-authored by bjohansebas
parent 9897eded61
commit b6f151362a
2 changed files with 4 additions and 4 deletions
+3 -3
View File
@@ -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';
+1 -1
View File
@@ -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 || ''))
})