From c14a6b385fa419ce67f115e853fb4a89d8bd8fad Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Sun, 22 Jul 2012 22:23:32 -0400 Subject: [PATCH] Clean up regexen; use common regex for numbers. Close gh-862. --- src/ajax.js | 2 +- src/attributes.js | 4 ++-- src/core.js | 7 +++++-- src/css.js | 23 +++++++++++------------ src/deprecated.js | 4 ++-- src/effects.js | 2 +- src/event.js | 8 ++++---- src/manipulation.js | 2 +- 8 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/ajax.js b/src/ajax.js index 053bd696b..304a41d48 100644 --- a/src/ajax.js +++ b/src/ajax.js @@ -12,7 +12,7 @@ var // Document location rquery = /\?/, rscript = /)<[^<]*)*<\/script>/gi, rts = /([?&])_=[^&]*/, - rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/, + rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+)|)|)/, // Keep a copy of the old load method _load = jQuery.fn.load, diff --git a/src/attributes.js b/src/attributes.js index c3890c459..e10ddced7 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -1,9 +1,9 @@ var nodeHook, boolHook, fixSpecified, - rclass = /[\n\t\r]/g, + rclass = /[\t\r\n]/g, rreturn = /\r/g, rtype = /^(?:button|input)$/i, rfocusable = /^(?:button|input|object|select|textarea)$/i, - rclickable = /^a(?:rea)?$/i, + rclickable = /^a(?:rea|)$/i, rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i, getSetAttribute = jQuery.support.getSetAttribute; diff --git a/src/core.js b/src/core.js index 01a3019e7..89e25978c 100644 --- a/src/core.js +++ b/src/core.js @@ -30,6 +30,9 @@ var return new jQuery.fn.init( selector, context, rootjQuery ); }, + // Used for matching numbers + core_pnum = /[\-+]?(?:\d*\.|)\d+(?:[eE][\-+]?\d+|)/.source, + // Used for detecting and trimming whitespace core_rnotwhite = /\S/, core_rspace = /\s+/, @@ -42,13 +45,13 @@ var rquickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/, // Match a standalone tag - rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/, + rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, // JSON RegExp rvalidchars = /^[\],:{}\s]*$/, rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g, rvalidescape = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g, - rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, + rvalidtokens = /"[^"\\\r\n]*"|true|false|null|-?(?:\d\d*\.|)\d+(?:[eE][\-+]?\d+|)/g, // Matches dashed string for camelizing rmsPrefix = /^-ms-/, diff --git a/src/css.js b/src/css.js index 41b978542..0b20b7c4c 100644 --- a/src/css.js +++ b/src/css.js @@ -1,25 +1,24 @@ var curCSS, iframe, iframeDoc, ralpha = /alpha\([^)]*\)/i, ropacity = /opacity=([^)]*)/, - rnumsplit = /^([\-+]?(?:\d*\.)?\d+)(.*)$/i, - rnumnonpx = /^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i, - rrelNum = /^([\-+])=([\-+.\de]+)/, + rposition = /^(top|right|bottom|left)$/, rmargin = /^margin/, + rnumsplit = new RegExp( "^(" + core_pnum + ")(.*)$", "i" ), + rnumnonpx = new RegExp( "^(" + core_pnum + ")(?!px)[a-z%]+$", "i" ), + rrelNum = new RegExp( "^([-+])=(" + core_pnum + ")", "i" ), elemdisplay = {}, - cssShow = { position: "absolute", visibility: "hidden", display: "block" }, - - // order is important! - cssExpand = [ "Top", "Right", "Bottom", "Left" ], - cssPrefixes = [ "Webkit", "O", "Moz", "ms" ], - rposition = /^(top|right|bottom|left)$/, - - eventsToggle = jQuery.fn.toggle, + cssShow = { position: "absolute", visibility: "hidden", display: "block" }, cssNormalTransform = { letterSpacing: 0, fontWeight: 400, lineHeight: 1 - }; + }, + + cssExpand = [ "Top", "Right", "Bottom", "Left" ], + cssPrefixes = [ "Webkit", "O", "Moz", "ms" ], + + eventsToggle = jQuery.fn.toggle; // return a css property mapped to a potentially vendor prefixed property function vendorPropName( style, name ) { diff --git a/src/deprecated.js b/src/deprecated.js index d165a8724..331755ff3 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -11,9 +11,9 @@ jQuery.uaMatch = function( ua ) { var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) || /(webkit)[ \/]([\w.]+)/.exec( ua ) || - /(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) || + /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || /(msie) ([\w.]+)/.exec( ua ) || - ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) || + ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || []; return { diff --git a/src/effects.js b/src/effects.js index 8ab41cbd3..dbca88650 100644 --- a/src/effects.js +++ b/src/effects.js @@ -1,6 +1,6 @@ var fxNow, timerId, rfxtypes = /^(?:toggle|show|hide)$/, - rfxnum = /^(?:([\-+])=)?([\d+.\-]+)([a-z%]*)$/i, + rfxnum = new RegExp( "^(?:([-+])=|)(" + core_pnum + ")([a-z%]*)$", "i" ), rrun = /queueHooks$/, animationPrefilters = [ defaultPrefilter ], tweeners = { diff --git a/src/event.js b/src/event.js index c3f164e6d..4703306ca 100644 --- a/src/event.js +++ b/src/event.js @@ -1,6 +1,6 @@ var rformElems = /^(?:textarea|input|select)$/i, - rtypenamespace = /^([^\.]*)?(?:\.(.+))?$/, - rhoverHack = /(?:^|\s)hover(\.\S+)?\b/, + rtypenamespace = /^([^\.]*|)(?:\.(.+)|)$/, + rhoverHack = /(?:^|\s)hover(\.\S+|)\b/, rkeyEvent = /^key/, rmouseEvent = /^(?:mouse|contextmenu)|click/, rfocusMorph = /^(?:focusinfocus|focusoutblur)$/, @@ -157,7 +157,7 @@ jQuery.event = { type = ( selector? special.delegateType : special.bindType ) || type; eventType = events[ type ] || []; origCount = eventType.length; - namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.)?") + "(\\.|$)") : null; + namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.|)") + "(\\.|$)") : null; // Remove matching events for ( j = 0; j < eventType.length; j++ ) { @@ -254,7 +254,7 @@ jQuery.event = { event.isTrigger = true; event.exclusive = exclusive; event.namespace = namespaces.join( "." ); - event.namespace_re = event.namespace? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)") : null; + event.namespace_re = event.namespace? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)") : null; ontype = type.indexOf( ":" ) < 0 ? "on" + type : ""; // Handle a global trigger diff --git a/src/manipulation.js b/src/manipulation.js index b248f51b8..d118529d4 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -14,7 +14,7 @@ function createSafeFragment( document ) { var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" + "header|hgroup|mark|meter|nav|output|progress|section|summary|time|video", - rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, + rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g, rleadingWhitespace = /^\s+/, rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, rtagName = /<([\w:]+)/, -- 2.39.5