config icon indicating copy to clipboard operation
config copied to clipboard

Prevent name collision with private methods from ancestors

Open vadtel opened this issue 1 year ago • 5 comments

I caught error when accessing an option named lambda

>> config['lambda']
# ArgumentError: tried to create Proc object without a block
from bundle/ruby/2.6.0/gems/config-2.2.3/lib/config/options.rb:161:in `lambda'

The methods used to access options are always public, so there is no need to use send. Using send can cause problems because it can call private and protected methods of the base classes. I replaced send with public_send. This will avoid the problems caused by send calling private and protected methods.

vadtel avatar Feb 13 '24 22:02 vadtel

@cjlarose are you happy with the change? I would like to merge it and release it as 5.2.0

pkuczynski avatar Feb 18 '24 19:02 pkuczynski

@vadtel tests are failing for Ruby 3.0. Would you mind having a look?

pkuczynski avatar Feb 18 '24 19:02 pkuczynski

@vadtel tests are failing for Ruby 3.0. Would you mind having a look?

It depends on the ostruct version We don't create singleton methods for fields with exclamation marks (bangs) how return respond_to?(name, true) - true The method_missing method only returns nil in one version of Ruby https://github.com/ruby/ostruct/commit/69cbbefd997f74b99b5135db8b9ef1ba97a31b43 May be we need to return "exit!" to constant?

vadtel avatar Feb 19 '24 15:02 vadtel

May be we need to return "exit!" to constant?

Yeah, possibly this would be the easiest solution. @cjlarose wdyt?

pkuczynski avatar Feb 19 '24 19:02 pkuczynski

Waiting for the feedback from @cjlarose before we merge it in and release it. Hopefully soon...

pkuczynski avatar Feb 19 '24 22:02 pkuczynski

Released with version 5.2.0

cjlarose avatar Mar 02 '24 01:03 cjlarose