Skip to content

Commit c14a6b3

Browse files
gibson042dmethvin
authored andcommitted
Clean up regexen; use common regex for numbers. Close jquerygh-862.
1 parent 74cc5b0 commit c14a6b3

File tree

8 files changed

+27
-25
lines changed

8 files changed

+27
-25
lines changed

src/ajax.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var // Document location
1212
rquery = /\?/,
1313
rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
1414
rts = /([?&])_=[^&]*/,
15-
rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,
15+
rurl = /^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+)|)|)/,
1616

1717
// Keep a copy of the old load method
1818
_load = jQuery.fn.load,

src/attributes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
var nodeHook, boolHook, fixSpecified,
2-
rclass = /[\n\t\r]/g,
2+
rclass = /[\t\r\n]/g,
33
rreturn = /\r/g,
44
rtype = /^(?:button|input)$/i,
55
rfocusable = /^(?:button|input|object|select|textarea)$/i,
6-
rclickable = /^a(?:rea)?$/i,
6+
rclickable = /^a(?:rea|)$/i,
77
rboolean = /^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,
88
getSetAttribute = jQuery.support.getSetAttribute;
99

src/core.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ var
3030
return new jQuery.fn.init( selector, context, rootjQuery );
3131
},
3232

33+
// Used for matching numbers
34+
core_pnum = /[\-+]?(?:\d*\.|)\d+(?:[eE][\-+]?\d+|)/.source,
35+
3336
// Used for detecting and trimming whitespace
3437
core_rnotwhite = /\S/,
3538
core_rspace = /\s+/,
@@ -42,13 +45,13 @@ var
4245
rquickExpr = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,
4346

4447
// Match a standalone tag
45-
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>)?$/,
48+
rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/,
4649

4750
// JSON RegExp
4851
rvalidchars = /^[\],:{}\s]*$/,
4952
rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g,
5053
rvalidescape = /\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,
51-
rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
54+
rvalidtokens = /"[^"\\\r\n]*"|true|false|null|-?(?:\d\d*\.|)\d+(?:[eE][\-+]?\d+|)/g,
5255

5356
// Matches dashed string for camelizing
5457
rmsPrefix = /^-ms-/,

src/css.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
var curCSS, iframe, iframeDoc,
22
ralpha = /alpha\([^)]*\)/i,
33
ropacity = /opacity=([^)]*)/,
4-
rnumsplit = /^([\-+]?(?:\d*\.)?\d+)(.*)$/i,
5-
rnumnonpx = /^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i,
6-
rrelNum = /^([\-+])=([\-+.\de]+)/,
4+
rposition = /^(top|right|bottom|left)$/,
75
rmargin = /^margin/,
6+
rnumsplit = new RegExp( "^(" + core_pnum + ")(.*)$", "i" ),
7+
rnumnonpx = new RegExp( "^(" + core_pnum + ")(?!px)[a-z%]+$", "i" ),
8+
rrelNum = new RegExp( "^([-+])=(" + core_pnum + ")", "i" ),
89
elemdisplay = {},
9-
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
10-
11-
// order is important!
12-
cssExpand = [ "Top", "Right", "Bottom", "Left" ],
13-
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ],
14-
rposition = /^(top|right|bottom|left)$/,
15-
16-
eventsToggle = jQuery.fn.toggle,
1710

11+
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
1812
cssNormalTransform = {
1913
letterSpacing: 0,
2014
fontWeight: 400,
2115
lineHeight: 1
22-
};
16+
},
17+
18+
cssExpand = [ "Top", "Right", "Bottom", "Left" ],
19+
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ],
20+
21+
eventsToggle = jQuery.fn.toggle;
2322

2423
// return a css property mapped to a potentially vendor prefixed property
2524
function vendorPropName( style, name ) {

src/deprecated.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jQuery.uaMatch = function( ua ) {
1111

1212
var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) ||
1313
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
14-
/(opera)(?:.*version)?[ \/]([\w.]+)/.exec( ua ) ||
14+
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
1515
/(msie) ([\w.]+)/.exec( ua ) ||
16-
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+))?/.exec( ua ) ||
16+
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
1717
[];
1818

1919
return {

src/effects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var fxNow, timerId,
22
rfxtypes = /^(?:toggle|show|hide)$/,
3-
rfxnum = /^(?:([\-+])=)?([\d+.\-]+)([a-z%]*)$/i,
3+
rfxnum = new RegExp( "^(?:([-+])=|)(" + core_pnum + ")([a-z%]*)$", "i" ),
44
rrun = /queueHooks$/,
55
animationPrefilters = [ defaultPrefilter ],
66
tweeners = {

src/event.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var rformElems = /^(?:textarea|input|select)$/i,
2-
rtypenamespace = /^([^\.]*)?(?:\.(.+))?$/,
3-
rhoverHack = /(?:^|\s)hover(\.\S+)?\b/,
2+
rtypenamespace = /^([^\.]*|)(?:\.(.+)|)$/,
3+
rhoverHack = /(?:^|\s)hover(\.\S+|)\b/,
44
rkeyEvent = /^key/,
55
rmouseEvent = /^(?:mouse|contextmenu)|click/,
66
rfocusMorph = /^(?:focusinfocus|focusoutblur)$/,
@@ -157,7 +157,7 @@ jQuery.event = {
157157
type = ( selector? special.delegateType : special.bindType ) || type;
158158
eventType = events[ type ] || [];
159159
origCount = eventType.length;
160-
namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
160+
namespaces = namespaces ? new RegExp("(^|\\.)" + namespaces.split(".").sort().join("\\.(?:.*\\.|)") + "(\\.|$)") : null;
161161

162162
// Remove matching events
163163
for ( j = 0; j < eventType.length; j++ ) {
@@ -254,7 +254,7 @@ jQuery.event = {
254254
event.isTrigger = true;
255255
event.exclusive = exclusive;
256256
event.namespace = namespaces.join( "." );
257-
event.namespace_re = event.namespace? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.)?") + "(\\.|$)") : null;
257+
event.namespace_re = event.namespace? new RegExp("(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)") : null;
258258
ontype = type.indexOf( ":" ) < 0 ? "on" + type : "";
259259

260260
// Handle a global trigger

src/manipulation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function createSafeFragment( document ) {
1414

1515
var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" +
1616
"header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",
17-
rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
17+
rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g,
1818
rleadingWhitespace = /^\s+/,
1919
rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
2020
rtagName = /<([\w:]+)/,

0 commit comments

Comments
 (0)