Skip to content

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

Merged
trekhleb merged 2 commits into
trekhleb:masterfrom
fauzan171:fix/replace-deprecated-substr
Jun 14, 2026
Merged

refactor: replace deprecated String.prototype.substr() with substring()#2181
trekhleb merged 2 commits into
trekhleb:masterfrom
fauzan171:fix/replace-deprecated-substr

Conversation

@fauzan171

Copy link
Copy Markdown
Contributor

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.

fauzan171 and others added 2 commits June 7, 2026 00:11
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.
@trekhleb trekhleb merged commit 4ed3123 into trekhleb:master Jun 14, 2026
1 check passed
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.

2 participants