Skip to content

refactor: replace deprecated String.prototype.substr() with substring()#2181

Open
fauzan171 wants to merge 1 commit into
trekhleb:masterfrom
fauzan171:fix/replace-deprecated-substr
Open

refactor: replace deprecated String.prototype.substr() with substring()#2181
fauzan171 wants to merge 1 commit into
trekhleb:masterfrom
fauzan171:fix/replace-deprecated-substr

Conversation

@fauzan171
Copy link
Copy Markdown

Problem

String.prototype.substr() is a legacy feature defined in Annex B of the ECMAScript specification and is deprecated. It may be removed from future JavaScript engine versions.

The codebase uses substr() in 5 places across 3 files.

Fix

Replaced all substr(start, length) calls with substring(start, start + length), which is the modern, standard alternative. The behavior is identical for all cases in this codebase.

Files changed:

  • src/algorithms/string/rabin-karp/rabinKarp.js — source code
  • src/algorithms/cryptography/polynomial-hash/__test__/SimplePolynomialHash.test.js — test
  • src/algorithms/cryptography/polynomial-hash/__test__/PolynomialHash.test.js — test

Conversion pattern:

// Before
text.substr(start, length)

// After
text.substring(start, start + length)

All 7 affected tests pass.

String.prototype.substr() is deprecated and may be removed in future
JavaScript engine versions (Annex B of the ECMAScript specification).

Replaced all occurrences in the codebase with String.prototype.substring():

- src/algorithms/string/rabin-karp/rabinKarp.js
- src/algorithms/cryptography/polynomial-hash/__test__/SimplePolynomialHash.test.js
- src/algorithms/cryptography/polynomial-hash/__test__/PolynomialHash.test.js

The behavior is identical since all substr(start, length) calls are
converted to substring(start, start + length) with the same arguments.

All existing tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant