Skip to main content

Bug Tracker

Side navigation

#10858 closed bug (fixed)

Opened November 22, 2011 05:12PM UTC

Closed December 09, 2011 01:29AM UTC

Last modified March 13, 2012 01:40PM UTC

css.js regular expressions are incomplete

Reported by: gibson042 Owned by: gibson042
Priority: low Milestone: 1.7.2
Component: css Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
Description

A review of pull request #610 revealed some flaws in css.js regular expressions with respect to CSS number values. They should be extended as follows in order to properly deal with explicit positives and non-integer reals:

rnumpx =   /^[-+]?\\d*(?:\\d|\\.\\d+)(?:px)?$/i
rnumnopx = /^[-+]?\\d*(?:\\d|\\.\\d+)(?!px)[^\\d\\s]+$/i

Test case: http://jsfiddle.net/7XGfE/

Attachments (0)
Change History (6)

Changed November 22, 2011 08:01PM UTC by timmywil comment:1

component: unfiledcss
milestone: None1.7.2
priority: undecidedlow
status: newopen

At first glance, this looks correct.

Changed November 26, 2011 03:58PM UTC by gibson042 comment:2

Performance analysis: http://jsperf.com/2011-11-23-regexp-complexity/2

I tested the decimal-rejecting expression against three decimal-accepting expressions. The net slowdown of .css(property) was generally within the margin of error reported by jsperf, especially on the fastest of the three (1%).

Since the fastest pattern is also the shortest, I recommend implementing it immediately:

rnumnopx = /^-?\\d*(?:\\d|\\.\\d+)(?!px)[^\\d\\s]+$/i
rnumpx = /^[-+]?\\d*(?:\\d|\\.\\d+)(?:px)?$/i

Changed November 28, 2011 03:08AM UTC by mikesherov comment:3

owner: → mikesherov
status: openassigned

Changed December 07, 2011 03:36AM UTC by mikesherov comment:4

owner: mikesherovgibson042

Changed December 07, 2011 07:52PM UTC by gibson042 comment:5

Changed December 09, 2011 01:29AM UTC by Richard Gibson comment:6

resolution: → fixed
status: assignedclosed

Fix #10858: CSS regexps recognize non-integer and explicit positive numbers.

Changeset: d6500cc8ded8d3d02e19a3ab831b6b9cf43e82ae