Skip to content

Commit 6ae222a

Browse files
committed
Core: Standardize indexOf comparisons
not present: `< 0` present: `> -1` at index: `=== N` (cherry picked from commit 53aa87f) Closes gh-1985
1 parent 18baae2 commit 6ae222a

File tree

7 files changed

+11
-10
lines changed

7 files changed

+11
-10
lines changed

src/ajax/jsonp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
2525
jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
2626
"url" :
2727
typeof s.data === "string" &&
28-
!( s.contentType || "" ).indexOf("application/x-www-form-urlencoded") &&
28+
( s.contentType || "" )
29+
.indexOf("application/x-www-form-urlencoded") === 0 &&
2930
rjsonp.test( s.data ) && "data"
3031
);
3132

src/ajax/load.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jQuery.fn.load = function( url, params, callback ) {
2424
self = this,
2525
off = url.indexOf(" ");
2626

27-
if ( off >= 0 ) {
27+
if ( off > -1 ) {
2828
selector = jQuery.trim( url.slice( off, url.length ) );
2929
url = url.slice( 0, off );
3030
}

src/attributes/classes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jQuery.fn.extend({
7676
j = 0;
7777
while ( (clazz = classes[j++]) ) {
7878
// Remove *all* instances
79-
while ( cur.indexOf( " " + clazz + " " ) >= 0 ) {
79+
while ( cur.indexOf( " " + clazz + " " ) > -1 ) {
8080
cur = cur.replace( " " + clazz + " ", " " );
8181
}
8282
}
@@ -149,7 +149,7 @@ jQuery.fn.extend({
149149
l = this.length;
150150
for ( ; i < l; i++ ) {
151151
if ( this[i].nodeType === 1 &&
152-
(" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) >= 0 ) {
152+
(" " + this[i].className + " ").replace(rclass, " ").indexOf( className ) > -1 ) {
153153

154154
return true;
155155
}

src/attributes/val.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jQuery.extend({
128128
while ( i-- ) {
129129
option = options[ i ];
130130
if ( (option.selected =
131-
jQuery.inArray( jQuery.valHooks.option.get( option ), values ) >= 0) ) {
131+
jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1) ) {
132132
optionSet = true;
133133
}
134134
}
@@ -149,7 +149,7 @@ jQuery.each([ "radio", "checkbox" ], function() {
149149
jQuery.valHooks[ this ] = {
150150
set: function( elem, value ) {
151151
if ( jQuery.isArray( value ) ) {
152-
return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) >= 0 );
152+
return ( elem.checked = jQuery.inArray( jQuery(elem).val(), value ) > -1 );
153153
}
154154
}
155155
};

src/event.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ jQuery.event = {
250250
return;
251251
}
252252

253-
if ( type.indexOf(".") >= 0 ) {
253+
if ( type.indexOf(".") > -1 ) {
254254
// Namespaced trigger; create a regexp to match event type in handle()
255255
namespaces = type.split(".");
256256
type = namespaces.shift();
@@ -460,7 +460,7 @@ jQuery.event = {
460460

461461
if ( matches[ sel ] === undefined ) {
462462
matches[ sel ] = handleObj.needsContext ?
463-
jQuery( sel, this ).index( cur ) >= 0 :
463+
jQuery( sel, this ).index( cur ) > -1 :
464464
jQuery.find( sel, this, null, [ cur ] ).length;
465465
}
466466
if ( matches[ sel ] ) {

src/manipulation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ jQuery.extend({
332332

333333
// #4087 - If origin and destination elements are the same, and this is
334334
// that element, do not do anything
335-
if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
335+
if ( selection && jQuery.inArray( elem, selection ) > -1 ) {
336336
continue;
337337
}
338338

src/traversing/findFilter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function winnow( elements, qualifier, not ) {
3333
}
3434

3535
return jQuery.grep( elements, function( elem ) {
36-
return ( jQuery.inArray( elem, qualifier ) >= 0 ) !== not;
36+
return ( jQuery.inArray( elem, qualifier ) > -1 ) !== not;
3737
});
3838
}
3939

0 commit comments

Comments
 (0)