Skip to content

Commit

Permalink
fix: Fix potential edge case in cordova.js detection (#284)
Browse files Browse the repository at this point in the history
Because `indexOf` returns -1 in the case of no match, and a subtraction
of string lengths can also potentially result in -1, we want to make
sure the index is NOT -1 before we try to substring with it.
  • Loading branch information
dpogue authored Nov 1, 2024
1 parent 788b62a commit 08a210d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/common/pluginloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ function findCordovaPath () {
var term = '/cordova.js';
for (var n = scripts.length - 1; n > -1; n--) {
var src = scripts[n].src.replace(/\?.*$/, ''); // Strip any query param (CB-6007).
if (src.indexOf(term) === (src.length - term.length)) {
var index = src.indexOf(term);
if (index !== -1 && index === (src.length - term.length)) {
path = src.substring(0, src.length - term.length) + '/';
break;
}
Expand Down

0 comments on commit 08a210d

Please sign in to comment.