Skip to content

Commit

Permalink
url,tools,benchmark: replace deprecated substr()
Browse files Browse the repository at this point in the history
  • Loading branch information
pluris committed Feb 28, 2024
1 parent 8e7da60 commit 094c72d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ module.exports = {
selector: 'ThrowStatement > CallExpression[callee.name=/Error$/]',
message: 'Use `new` keyword when throwing an `Error`.',
},
{
selector: "CallExpression[callee.property.name='substr']",
message: 'Use String.prototype.slice() or String.prototype.substring() instead of String.prototype.substr()',
},
{
selector: "CallExpression[callee.name='isNaN']",
message: 'Use Number.isNaN() instead of the global isNaN() function.',
Expand Down
2 changes: 1 addition & 1 deletion benchmark/http/bench-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function main({ len, n }) {
let header = `GET /hello HTTP/1.1${CRLF}Content-Type: text/plain${CRLF}`;

for (let i = 0; i < len; i++) {
header += `X-Filler${i}: ${Math.random().toString(36).substr(2)}${CRLF}`;
header += `X-Filler${i}: ${Math.random().toString(36).substring(2)}${CRLF}`;
}
header += CRLF;

Expand Down
2 changes: 1 addition & 1 deletion lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ Url.prototype.resolveObject = function resolveObject(relative) {
srcPath.unshift('');
}

if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
if (hasTrailingSlash && (srcPath.join('/').slice(-1) !== '/')) {
srcPath.push('');
}

Expand Down
4 changes: 2 additions & 2 deletions tools/doc/html.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,8 @@ function versionSort(a, b) {
b = minVersion(b).trim();
let i = 0; // Common prefix length.
while (i < a.length && i < b.length && a[i] === b[i]) i++;
a = a.substr(i);
b = b.substr(i);
a = a.substring(i);
b = b.substring(i);
return +b.match(numberRe)[0] - +a.match(numberRe)[0];
}

Expand Down
4 changes: 2 additions & 2 deletions tools/doc/json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ function parseSignature(text, sig) {

const eq = sigParam.indexOf('=');
if (eq !== -1) {
defaultValue = sigParam.substr(eq + 1);
sigParam = sigParam.substr(0, eq);
defaultValue = sigParam.substring(eq + 1);
sigParam = sigParam.substring(0, eq);
}

// At this point, the name should match. If it doesn't find one that does.
Expand Down

0 comments on commit 094c72d

Please sign in to comment.