Bug Tracker

Modify

Ticket #10858 (closed bug: fixed)

Opened 2 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

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/

Change History

comment:1 Changed 2 years ago by timmywil

  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to css
  • Milestone changed from None to 1.7.2

At first glance, this looks correct.

comment:2 Changed 2 years ago by gibson042

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

comment:3 Changed 2 years ago by mikesherov

  • Owner set to mikesherov
  • Status changed from open to assigned

comment:4 Changed 2 years ago by mikesherov

  • Owner changed from mikesherov to gibson042

comment:6 Changed 2 years ago by Richard Gibson

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Changeset: d6500cc8ded8d3d02e19a3ab831b6b9cf43e82ae

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.