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

Update Constraint#matches_constraint? #157

Merged
merged 1 commit into from Oct 19, 2023
Merged

Conversation

thorion3006
Copy link
Contributor

About the changes

context_value.upcase! if self.case_insensitive
is a frozen string when # frozen-string-literal: true is used, so calling #upcase! throws FrozenError

Closes #156

Copy link
Collaborator

@gardleopard gardleopard left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution!

@coveralls
Copy link

Pull Request Test Coverage Report for Build 6563818978

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.08%) to 97.189%

Totals Coverage Status
Change from base Build 6532861514: 0.08%
Covered Lines: 2524
Relevant Lines: 2597

💛 - Coveralls

@sighphyre sighphyre merged commit 78bbf9d into Unleash:main Oct 19, 2023
23 checks passed
Comment on lines 109 to 112
v.map!(&:upcase) if self.case_insensitive
context_value.upcase! if self.case_insensitive
context_value = context_value.upcase if self.case_insensitive

OPERATORS[self.operator].call(context_value, v)
Copy link
Collaborator

@rarruda rarruda Oct 19, 2023

Choose a reason for hiding this comment

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

would have been a prettier solution:

Suggested change
v.map!(&:upcase) if self.case_insensitive
context_value.upcase! if self.case_insensitive
context_value = context_value.upcase if self.case_insensitive
OPERATORS[self.operator].call(context_value, v)
OPERATORS[self.operator].call(
context_value.then{|c| self.case_insensitive ? c.upcase : c} ,
v.then{|v| self.case_insensitive ? v.map(&:upcase) : v}
)

Copy link
Collaborator

@rarruda rarruda Oct 19, 2023

Choose a reason for hiding this comment

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

the same issue will reappear if the values in v are frozen.

Additionally would have been nice with a unit test that triggers the bug previously, and wouldn't trigger now, so to prevent possible regressions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

note that using ! methods in general is to be avoided, and specially on user provided data is dangerous, as you shouldn't be altering data provided / referenced by the user. (if he is to use again later on, it will be changed by this method in the SDK).

Copy link
Member

@sighphyre sighphyre Oct 20, 2023

Choose a reason for hiding this comment

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

the same issue will reappear if the values in v are frozen.

Unless you're doing something super weird, the values in v should only come from internal code. If that starts to fail then we have bigger problems

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