diff --git a/package.json b/package.json index ec6dee78d..a979e28f5 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "prefer-destructuring": "error", "unicorn/no-for-loop": "error", "unicorn/prefer-includes": "error", - "unicorn/prefer-string-slice": "warn", + "unicorn/prefer-string-slice": "error", "unicorn/filename-case": "warn", "unicorn/prefer-query-selector": "error" } diff --git a/src/main/zapHomeFiles/hud/display.js b/src/main/zapHomeFiles/hud/display.js index 3edb37065..8f9c65b3d 100644 --- a/src/main/zapHomeFiles/hud/display.js +++ b/src/main/zapHomeFiles/hud/display.js @@ -754,7 +754,7 @@ Vue.component('site-tree-node', { if ((name.match(/\//g) || []).length > 2) { // If there are more than 2 slashes just show last url element // The first 2 slashes will be http(s)://... - name = name.substring(name.lastIndexOf('/') + 1); + name = name.slice(name.lastIndexOf('/') + 1); } if (isLeaf) { diff --git a/src/main/zapHomeFiles/hud/target/inject.js b/src/main/zapHomeFiles/hud/target/inject.js index 354ac5557..dcb2ee3a2 100644 --- a/src/main/zapHomeFiles/hud/target/inject.js +++ b/src/main/zapHomeFiles/hud/target/inject.js @@ -33,7 +33,7 @@ const injection = (function () { const r = Math.floor(Math.random() * 1000); const tabId = String(millis) + '-' + r; - return tabId.substring(6); + return tabId.slice(6); } /* TARGET INTERACTIONS */ @@ -623,8 +623,8 @@ const injection = (function () { if (zapReplaceOffset > 0) { // Hide the zapHudReplaceReq injected when resending a message in the browser // But don't loose any fragment - const fragment = window.location.hash.substr(1); - let origUrl = window.location.href.substring(0, zapReplaceOffset - 1); + const fragment = window.location.hash.slice(1); + let origUrl = window.location.href.slice(0, zapReplaceOffset - 1); if (fragment) { origUrl += '#' + fragment; } diff --git a/src/main/zapHomeFiles/hud/tools/commonAlerts.js b/src/main/zapHomeFiles/hud/tools/commonAlerts.js index 1a223084f..5ecdd593f 100644 --- a/src/main/zapHomeFiles/hud/tools/commonAlerts.js +++ b/src/main/zapHomeFiles/hud/tools/commonAlerts.js @@ -85,7 +85,7 @@ const CommonAlerts = (function () { if (zapReplaceOffset > 0) { // Strip off the string used for resending in the browser // Will be preceded by ? or & - origTarget = origTarget.substring(0, zapReplaceOffset - 1); + origTarget = origTarget.slice(0, zapReplaceOffset - 1); } let target = origTarget; diff --git a/src/main/zapHomeFiles/hud/tools/utils/alertUtils.js b/src/main/zapHomeFiles/hud/tools/utils/alertUtils.js index 86eeb3b44..e87cb9e39 100644 --- a/src/main/zapHomeFiles/hud/tools/utils/alertUtils.js +++ b/src/main/zapHomeFiles/hud/tools/utils/alertUtils.js @@ -70,7 +70,7 @@ const alertUtils = (function () { if (target.indexOf('?') > 0) { // Remove any url params - target = target.substring(0, target.indexOf('?')); + target = target.slice(0, target.indexOf('?')); } return apiCallWithResponse('alert', 'view', 'alertsByRisk', {url: target, recurse: 'false'}); diff --git a/src/main/zapHomeFiles/hud/utils.js b/src/main/zapHomeFiles/hud/utils.js index 61cfebcaf..2fe62014d 100644 --- a/src/main/zapHomeFiles/hud/utils.js +++ b/src/main/zapHomeFiles/hud/utils.js @@ -43,27 +43,27 @@ const utils = (function () { function parseRequestHeader(headerText) { const header = {}; - header.method = headerText.substring(0, headerText.indexOf(' ')); - headerText = headerText.substring(headerText.indexOf(' ') + 1); + header.method = headerText.slice(0, headerText.indexOf(' ')); + headerText = headerText.slice(headerText.indexOf(' ') + 1); - header.uri = headerText.substring(0, headerText.indexOf(' ')); - headerText = headerText.substring(headerText.indexOf(' ') + 1); + header.uri = headerText.slice(0, headerText.indexOf(' ')); + headerText = headerText.slice(headerText.indexOf(' ') + 1); - header.version = headerText.substring(0, headerText.indexOf('\r')); - headerText = headerText.substring(headerText.indexOf('\n') + 1); + header.version = headerText.slice(0, headerText.indexOf('\r')); + headerText = headerText.slice(headerText.indexOf('\n') + 1); header.fields = {}; while (headerText !== '') { - const field = headerText.substring(0, headerText.indexOf(':')); - headerText = headerText.substring(headerText.indexOf(':') + 2); + const field = headerText.slice(0, headerText.indexOf(':')); + headerText = headerText.slice(headerText.indexOf(':') + 2); let value; if (!headerText.includes('\n')) { value = headerText; headerText = ''; } else { - value = headerText.substring(0, headerText.indexOf('\n')); - headerText = headerText.substring(headerText.indexOf('\n') + 1); + value = headerText.slice(0, headerText.indexOf('\n')); + headerText = headerText.slice(headerText.indexOf('\n') + 1); } header.fields[field] = value; @@ -78,22 +78,22 @@ const utils = (function () { function parseResponseHeader(headerText) { const header = {}; - header.version = headerText.substring(0, headerText.indexOf(' ')); - headerText = headerText.substring(headerText.indexOf(' ') + 1); + header.version = headerText.slice(0, headerText.indexOf(' ')); + headerText = headerText.slice(headerText.indexOf(' ') + 1); - header.status = headerText.substring(0, headerText.indexOf(' ')); - headerText = headerText.substring(headerText.indexOf(' ') + 1); + header.status = headerText.slice(0, headerText.indexOf(' ')); + headerText = headerText.slice(headerText.indexOf(' ') + 1); - header.reason = headerText.substring(0, headerText.indexOf(' ')); - headerText = headerText.substring(headerText.indexOf(' ') + 1); + header.reason = headerText.slice(0, headerText.indexOf(' ')); + headerText = headerText.slice(headerText.indexOf(' ') + 1); header.fields = {}; while (headerText !== '') { - const field = headerText.substring(0, headerText.indexOf(':')); - headerText = headerText.substring(headerText.indexOf(':') + 2); + const field = headerText.slice(0, headerText.indexOf(':')); + headerText = headerText.slice(headerText.indexOf(':') + 2); - const value = headerText.substring(0, headerText.indexOf('\n')); - headerText = headerText.substring(headerText.indexOf('\n') + 1); + const value = headerText.slice(0, headerText.indexOf('\n')); + headerText = headerText.slice(headerText.indexOf('\n') + 1); header.fields[field] = value; } @@ -136,7 +136,7 @@ const utils = (function () { let end = url.indexOf('&', start); end = end === -1 ? url.length : end; - return url.substring(start, end); + return url.slice(start, end); } /* STORAGE */ @@ -650,7 +650,7 @@ const utils = (function () { scheme = 'http'; } - return scheme + '://' + domain + url.substring(url.indexOf(domain) + domain.length); + return scheme + '://' + domain + url.slice(url.indexOf(domain) + domain.length); }) .catch(errorHandler); } @@ -665,8 +665,8 @@ const utils = (function () { // Construct the stack trace const lines = error.stack.split('\n').slice(0, -1); lines.forEach(line => { - const functionName = line.substring(0, line.indexOf('/')); - const urlAndLineNo = line.substring(line.indexOf('http'), line.length - 1); + const functionName = line.slice(0, line.indexOf('/')); + const urlAndLineNo = line.slice(line.indexOf('http'), -1); const parts = urlAndLineNo.split(':'); let url = parts[0] + ':' + parts[1]; let lineNo = parts[2] + ':' + parts[3];