-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
The :allow_empty
option is ignored when given a frozen string
#71
Comments
Given #53, please try to convince me why you think this is a bug?
|
Thanks for the response, and the context with regard to the previous issue. That's helpful. I think it's a regression, primarily because it doesn't respect the Secondly, it leads to unexpected behavior. Which in turn can be challenging to debug. Let me explain: An often preferred coding style is using coercion over type checking. Which is why it'd be somewhat common to coerce the given value to the expected type, which is how we end up passing Showing an example, I would expect these to behave similar, since they are functionally the same: StripAttributes.strip("") # => nil
StripAttributes.strip(nil.to_s) # => "" But as you can see, the results are different. And confusing. Since many devs may not know that It does make sense to return the given Leading to this confusing behavior: StripAttributes.strip("", allow_empty: false) # => nil <-- Correct. The flag specifies no empty values
StripAttributes.strip(nil.to_s, allow_empty: false) # => "" <-- Wrong. I specified "no empty values". this should be nil Whether the empty string is frozen or not, doesn't matter here. It's essentially a noop. But the return value is not correct. We need to apply the same logic as we do at the bottom of the method. I can open a PR to update it, if you're on the same page. |
I believe this was fixed by #78 |
This snippet should return
nil
, since its given a blank string andallow_empty: false
The reason is this guard against frozen strings:
https://github.com/rmm5t/strip_attributes/blob/master/lib/strip_attributes.rb#L55
The text was updated successfully, but these errors were encountered: