Log In
Log In
Places
All Projects
Status Monitor
Collapse sidebar
obs:server:fedora:2.10:testing
obs-server
obs-server-2.10-0036-api-Pass-keyword-args-prop...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File obs-server-2.10-0036-api-Pass-keyword-args-properly-for-Ruby-3.0.patch of Package obs-server
From aa7fc9df38f33166977a9bb617517ab502260eed Mon Sep 17 00:00:00 2001 From: Oleg Girko <ol@infoserver.lv> Date: Sun, 18 Jul 2021 23:03:38 +0100 Subject: [PATCH] [api] Pass keyword args properly for Ruby 3.0. In Ruby 3.0, *args in argument list captutes only positional arguments, but not keyword ones. Hence, **kwargs should be added to capture keyword arguments to pass them correctly to wrapped function. However, this can't be done unconditionally because it has unintended consequences in Ruby 2 when passing something convertible to hash (that has to_hash method) as the last argement to any wrapped function: it is converted to hash and passed as keyword arguments. This leads to miserable failure when passing ActionController::Parameters, for example: its to_hash method raises ActionController::UnfilteredParameters exception if these parameters are not marked explicitly as safe. The only solution I see is to define wrapper different way for Ruby 3 and Ruby 2: with and without **kwargs argument respectively. Signed-off-by: Oleg Girko <ol@infoserver.lv> --- src/api/lib/backend/remember_location.rb | 25 +++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/api/lib/backend/remember_location.rb b/src/api/lib/backend/remember_location.rb index 74d2953929..bd9e910318 100644 --- a/src/api/lib/backend/remember_location.rb +++ b/src/api/lib/backend/remember_location.rb @@ -9,13 +9,24 @@ module Backend filtering << method_name - define_singleton_method(method_name) do |*args, &block| - Thread.current[:_influxdb_obs_backend_api_method] = method_name.to_s - Thread.current[:_influxdb_obs_backend_api_module] = name - original_method.call(*args, &block) - ensure - Thread.current[:_influxdb_obs_backend_api_method] = nil - Thread.current[:_influxdb_obs_backend_api_module] = nil + if RUBY_VERSION.split('.')[0].to_i >= 3 + define_singleton_method(method_name) do |*args, **kwargs, &block| + Thread.current[:_influxdb_obs_backend_api_method] = method_name.to_s + Thread.current[:_influxdb_obs_backend_api_module] = name + original_method.call(*args, **kwargs, &block) + ensure + Thread.current[:_influxdb_obs_backend_api_method] = nil + Thread.current[:_influxdb_obs_backend_api_module] = nil + end + else + define_singleton_method(method_name) do |*args, &block| + Thread.current[:_influxdb_obs_backend_api_method] = method_name.to_s + Thread.current[:_influxdb_obs_backend_api_module] = name + original_method.call(*args, &block) + ensure + Thread.current[:_influxdb_obs_backend_api_method] = nil + Thread.current[:_influxdb_obs_backend_api_module] = nil + end end end -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Contact
Support
@OBShq
The Open Build Service is an
openSUSE project
.
Log In
Places
Places
All Projects
Status Monitor