mirror of
https://github.com/hanzoai/session.git
synced 2026-09-24 17:02:35 +00:00
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:
committed by
GitHub
co-authored by
bjohansebas
parent
9897eded61
commit
b6f151362a
@@ -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
@@ -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 || ''))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user