Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing ruleset shorthands in ruby 3.2 #140

Merged
merged 1 commit into from Aug 29, 2023

Conversation

jdelStrother
Copy link
Contributor

@jdelStrother jdelStrother commented Aug 29, 2023

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

  • CHANGELOG.md updated with short summary

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

```ruby
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.
Copy link
Contributor

@grosser grosser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the old one seems a tad neater, but this one is simpler so 👍 :D

@grosser grosser merged commit 52ecb27 into premailer:master Aug 29, 2023
5 of 6 checks passed
@grosser
Copy link
Contributor

grosser commented Aug 29, 2023

1.15.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants