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
Conversation
There was a problem hiding this 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!
Pull Request Test Coverage Report for Build 6563818978
💛 - Coveralls |
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) |
There was a problem hiding this comment.
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:
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} | |
) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
About the changes
unleash-client-ruby/lib/unleash/constraint.rb
Line 110 in e935495
# frozen-string-literal: true
is used, so calling#upcase!
throwsFrozenError
Closes #156