Skip to content

Commit

Permalink
Replace deprecated String.prototype.substr()
Browse files Browse the repository at this point in the history
String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with slice() or substring() which work similarily but aren't deprecated.
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>

PR-URL: #163
Credit: @CommanderRoot
Close: #163
Reviewed-by: @lamweili
  • Loading branch information
CommanderRoot authored and isaacs committed Nov 29, 2022
1 parent 9ae5d49 commit 0148432
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions minimatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class Minimatch {
negateOffset++
}

if (negateOffset) this.pattern = pattern.substr(negateOffset)
if (negateOffset) this.pattern = pattern.slice(negateOffset)
this.negate = negate
}

Expand Down Expand Up @@ -619,7 +619,7 @@ class Minimatch {
} catch (er) {
// not a valid class!
sp = this.parse(cs, SUBPARSE)
re = re.substr(0, reClassStart) + '\\[' + sp[0] + '\\]'
re = re.substring(0, reClassStart) + '\\[' + sp[0] + '\\]'
hasMagic = hasMagic || sp[1]
inClass = false
continue
Expand Down Expand Up @@ -652,9 +652,9 @@ class Minimatch {
// this is a huge pita. We now have to re-walk
// the contents of the would-be class to re-translate
// any characters that were passed through as-is
cs = pattern.substr(classStart + 1)
cs = pattern.slice(classStart + 1)
sp = this.parse(cs, SUBPARSE)
re = re.substr(0, reClassStart) + '\\[' + sp[0]
re = re.substring(0, reClassStart) + '\\[' + sp[0]
hasMagic = hasMagic || sp[1]
}

Expand Down
2 changes: 1 addition & 1 deletion test/escaping.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var pre = 'x' // prepended to the testable character
var post = 'y' // appended to the testable character

function escapeChar (cc) {
return '"\\u' + ('000' + cc.toString(16).toUpperCase()).substr(-4) + '"'
return '"\\u' + ('000' + cc.toString(16).toUpperCase()).slice(-4) + '"'
}

tap.test('escaping tests', function (t) {
Expand Down

0 comments on commit 0148432

Please sign in to comment.