From 0d5c3a68a092401089c9242bdafdb1b2534feb6a Mon Sep 17 00:00:00 2001 From: John Resig Date: Sun, 19 Jul 2009 13:21:51 +0000 Subject: [PATCH] Standardizing on .test() and .exec() - moving away from using .match() for RegExp. Fixes jQuery bug #4113. --- src/ajax.js | 12 ++++++------ src/attributes.js | 6 +++--- src/core.js | 2 +- src/css.js | 6 +++--- src/fx.js | 2 +- src/manipulation.js | 6 +++--- src/selector.js | 6 +++--- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index beed45fbf..2e4c740da 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -187,15 +187,15 @@ jQuery.extend({ // Handle JSONP Parameter Callbacks if ( s.dataType == "jsonp" ) { if ( type == "GET" ) { - if ( !s.url.match(jsre) ) - s.url += (s.url.match(/\?/) ? "&" : "?") + (s.jsonp || "callback") + "=?"; - } else if ( !s.data || !s.data.match(jsre) ) + if ( jsre.test( !s.url ) ) + s.url += (/\?/.test( s.url ) ? "&" : "?") + (s.jsonp || "callback") + "=?"; + } else if ( !s.data || !jsre.test(s.data) ) s.data = (s.data ? s.data + "&" : "") + (s.jsonp || "callback") + "=?"; s.dataType = "json"; } // Build temporary JSONP function - if ( s.dataType == "json" && (s.data && s.data.match(jsre) || s.url.match(jsre)) ) { + if ( s.dataType == "json" && (s.data && jsre.test(s.data) || jsre.test(s.url)) ) { jsonp = "jsonp" + jsc++; // Replace the =? sequence both in the query string and the data @@ -228,12 +228,12 @@ jQuery.extend({ // try replacing _= if it is there var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2"); // if nothing was replaced, add timestamp to the end - s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") + "_=" + ts : ""); + s.url = ret + ((ret == s.url) ? (/\?/.test(s.url) ? "&" : "?") + "_=" + ts : ""); } // If data is available, append data to url for get requests if ( s.data && type == "GET" ) { - s.url += (s.url.match(/\?/) ? "&" : "?") + s.data; + s.url += (/\?/.test(s.url) ? "&" : "?") + s.data; } // Watch for a new set of requests diff --git a/src/attributes.js b/src/attributes.js index 9e66df0ce..041bb29fc 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -214,7 +214,7 @@ jQuery.extend({ if ( name in elem && notxml && !special ) { if ( set ){ // We can't allow the type property to be changed (since it causes problems in IE) - if ( name == "type" && elem.nodeName.match(/(button|input)/i) && elem.parentNode ) + if ( name == "type" && /(button|input)/i.test(elem.nodeName) && elem.parentNode ) throw "type property can't be changed"; elem[ name ] = value; @@ -230,9 +230,9 @@ jQuery.extend({ var attributeNode = elem.getAttributeNode( "tabIndex" ); return attributeNode && attributeNode.specified ? attributeNode.value - : elem.nodeName.match(/(button|input|object|select|textarea)/i) + : /(button|input|object|select|textarea)/i.test(elem.nodeName) ? 0 - : elem.nodeName.match(/^(a|area)$/i) && elem.href + : /^(a|area)$/i.test(elem.nodeName) && elem.href ? 0 : undefined; } diff --git a/src/core.js b/src/core.js index a74f0fec9..2a064c27e 100644 --- a/src/core.js +++ b/src/core.js @@ -474,7 +474,7 @@ jQuery.extend({ // It's included for backwards compatibility and plugins, // although they should work to migrate away. browser: { - version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1], + version: (/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/.exec(userAgent) || [0,'0'])[1], safari: /webkit/.test( userAgent ), opera: /opera/.test( userAgent ), msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ), diff --git a/src/css.js b/src/css.js index 94a021b6a..2395bdf59 100644 --- a/src/css.js +++ b/src/css.js @@ -75,7 +75,7 @@ jQuery.extend({ } return style.filter && style.filter.indexOf("opacity=") >= 0 ? - (parseFloat( style.filter.match(/opacity=([^)]*)/)[1] ) / 100) + '': + (parseFloat( /opacity=([^)]*)/.exec(style.filter)[1] ) / 100) + '': ""; } @@ -129,7 +129,7 @@ jQuery.extend({ // IE uses filters for opacity if ( !jQuery.support.opacity && name === "opacity" && elem.currentStyle ) { - ret = (elem.currentStyle.filter || "").match(/opacity=([^)]*)/) ? + ret = /opacity=([^)]*)/.test(elem.currentStyle.filter || "") ? (parseFloat(RegExp.$1) / 100) + "" : ""; @@ -207,4 +207,4 @@ jQuery.extend({ for ( var name in options ) elem.style[ name ] = old[ name ]; } -}); \ No newline at end of file +}); diff --git a/src/fx.js b/src/fx.js index c5c05468a..65bb3f143 100644 --- a/src/fx.js +++ b/src/fx.js @@ -132,7 +132,7 @@ jQuery.fn.extend({ if ( /toggle|show|hide/.test(val) ) e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop ); else { - var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/), + var parts = /^([+-]=)?([\d+-.]+)(.*)$/.exec(val), start = e.cur(true) || 0; if ( parts ) { diff --git a/src/manipulation.js b/src/manipulation.js index 55017c196..20a107565 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -286,7 +286,7 @@ jQuery.extend({ if ( typeof elem === "string" ) { // Fix "XHTML"-style tags in all browsers elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){ - return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ? + return /^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i.test(tag) ? all : front + ">"; }); @@ -302,7 +302,7 @@ jQuery.extend({ !tags.indexOf("", "" ] || - tags.match(/^<(thead|tbody|tfoot|colg|cap)/) && + /^<(thead|tbody|tfoot|colg|cap)/.test(tags) && [ 1, "", "
" ] || !tags.indexOf(" 1 || /^\w/.test(match[3]) ) { + if ( chunker.exec(match[3]).length > 1 || /^\w/.test(match[3]) ) { match[3] = Sizzle(match[3], null, null, curLoop); } else { var ret = Sizzle.filter(match[3], curLoop, inplace, true ^ not);