Skip to content

Commit d6500cc

Browse files
gibson042dmethvin
authored andcommitted
Fix #10858: CSS regexps recognize non-integer and explicit positive numbers.
1 parent 8f5f1b2 commit d6500cc

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

src/css.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ var ralpha = /alpha\([^)]*\)/i,
44
ropacity = /opacity=([^)]*)/,
55
// fixed for IE9, see #8346
66
rupper = /([A-Z]|^ms)/g,
7-
rnumpx = /^-?\d+(?:px)?$/i,
8-
rnumnopx = /^-?\d+(?!px)[^\d\s]+$/i,
7+
rnum = /^[\-+]?(?:\d*\.)?\d+$/i,
8+
rnumnonpx = /^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i,
99
rrelNum = /^([\-+])=([\-+.\de]+)/,
1010
rmargin = /^margin/,
1111

@@ -181,17 +181,9 @@ jQuery.each(["height", "width"], function( i, name ) {
181181
},
182182

183183
set: function( elem, value ) {
184-
if ( rnumpx.test( value ) ) {
185-
// ignore negative width and height values #1599
186-
value = parseFloat( value );
187-
188-
if ( value >= 0 ) {
189-
return value + "px";
190-
}
191-
192-
} else {
193-
return value;
194-
}
184+
return rnum.test( value ) ?
185+
value + "px" :
186+
value;
195187
}
196188
};
197189
});
@@ -274,7 +266,7 @@ if ( document.defaultView && document.defaultView.getComputedStyle ) {
274266
// A tribute to the "awesome hack by Dean Edwards"
275267
// WebKit uses "computed value (percentage if specified)" instead of "used value" for margins
276268
// which is against the CSSOM draft spec: http://dev.w3.org/csswg/cssom/#resolved-values
277-
if ( !jQuery.support.pixelMargin && computedStyle && rmargin.test( name ) && rnumnopx.test( ret ) ) {
269+
if ( !jQuery.support.pixelMargin && computedStyle && rmargin.test( name ) && rnumnonpx.test( ret ) ) {
278270
width = style.width;
279271
style.width = ret;
280272
ret = computedStyle.width;
@@ -302,7 +294,7 @@ if ( document.documentElement.currentStyle ) {
302294

303295
// If we're not dealing with a regular pixel number
304296
// but a number that has a weird ending, we need to convert it to pixels
305-
if ( rnumnopx.test( ret ) ) {
297+
if ( rnumnonpx.test( ret ) ) {
306298

307299
// Remember the original values
308300
left = style.left;

0 commit comments

Comments
 (0)