Skip to content

Commit 08a210d

Browse files
authored
fix: Fix potential edge case in cordova.js detection (#284)
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.
1 parent 788b62a commit 08a210d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/common/pluginloader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ function findCordovaPath () {
101101
var term = '/cordova.js';
102102
for (var n = scripts.length - 1; n > -1; n--) {
103103
var src = scripts[n].src.replace(/\?.*$/, ''); // Strip any query param (CB-6007).
104-
if (src.indexOf(term) === (src.length - term.length)) {
104+
var index = src.indexOf(term);
105+
if (index !== -1 && index === (src.length - term.length)) {
105106
path = src.substring(0, src.length - term.length) + '/';
106107
break;
107108
}

0 commit comments

Comments
 (0)