premailer / css_parser

Ruby CSS Parser
Other
279 stars 110 forks source link

Fix parsing ruleset shorthands in ruby 3.2 #140

Closed jdelStrother closed 1 year ago

jdelStrother commented 1 year ago

For reasons I've not been smart enough to figure out, there's a difference in matching between 3.1 and 3.2

RE_LENGTH_OR_PERCENTAGE =
Regexp.new('([\-]*(([0-9]*\.[0-9]+)|[0-9]+)(e[mx]+|px|[cm]+m|p[tc+]|in|\%))',
Regexp::IGNORECASE)
RE_BACKGROUND_POSITION = Regexp.new("((((#{RE_LENGTH_OR_PERCENTAGE})|left|center|right|top|bottom)[\s]*){1,2})", Regexp::IGNORECASE | Regexp::EXTENDED)
"  top right".match(RE_BACKGROUND_POSITION)

matches top right on ruby 3.1, but just top on 3.2.

The previous regexp looked something like /((top|right)\s*){1,2}/ to match 1 or 2 positions separated by optional whitespace. This updates it to /((top|right)\s+(top|right))|(top|right)/, which seems to give consistent matching behaviour between ruby 3.1 & 3.2

Pre-Merge Checklist

grosser commented 1 year ago

1.15.0