Skip to content

Commit ef6a210

Browse files
Jungku Leetargos
Jungku Lee
authored andcommitted
url,tools,benchmark: replace deprecated substr()
PR-URL: #51546 Refs: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/substr Reviewed-By: Jithil P Ponnan <jithil@outlook.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent e016e95 commit ef6a210

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

.eslintrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ module.exports = {
212212
selector: 'ThrowStatement > CallExpression[callee.name=/Error$/]',
213213
message: 'Use `new` keyword when throwing an `Error`.',
214214
},
215+
{
216+
selector: "CallExpression[callee.property.name='substr']",
217+
message: 'Use String.prototype.slice() or String.prototype.substring() instead of String.prototype.substr()',
218+
},
215219
{
216220
selector: "CallExpression[callee.name='isNaN']",
217221
message: 'Use Number.isNaN() instead of the global isNaN() function.',

benchmark/http/bench-parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function main({ len, n }) {
4646
let header = `GET /hello HTTP/1.1${CRLF}Content-Type: text/plain${CRLF}`;
4747

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

lib/url.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ Url.prototype.resolveObject = function resolveObject(relative) {
958958
srcPath.unshift('');
959959
}
960960

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

tools/doc/html.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,8 @@ function versionSort(a, b) {
394394
b = minVersion(b).trim();
395395
let i = 0; // Common prefix length.
396396
while (i < a.length && i < b.length && a[i] === b[i]) i++;
397-
a = a.substr(i);
398-
b = b.substr(i);
397+
a = a.substring(i);
398+
b = b.substring(i);
399399
return +b.match(numberRe)[0] - +a.match(numberRe)[0];
400400
}
401401

tools/doc/json.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ function parseSignature(text, sig) {
320320

321321
const eq = sigParam.indexOf('=');
322322
if (eq !== -1) {
323-
defaultValue = sigParam.substr(eq + 1);
324-
sigParam = sigParam.substr(0, eq);
323+
defaultValue = sigParam.substring(eq + 1);
324+
sigParam = sigParam.substring(0, eq);
325325
}
326326

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

0 commit comments

Comments
 (0)