From 5dcb245eacfa66f7fba794e61a45ebd21ea7fae9 Mon Sep 17 00:00:00 2001 From: Ted Johansson Date: Thu, 12 Jan 2023 19:12:20 +0800 Subject: [PATCH] FIX: Ruby 2 backward compatible plugin logout redirect (#19845) This is a very subtle one. Setting the redirect URL is done by passing a hash through a Discourse event. This is broken on Ruby 2 since the support for keyword arguments in events was added. In Ruby 2 the last argument is cast to keyword arguments if it is a hash. The key point here is that creates a new copy of the hash, so what the plugin is modifying is not the hash that was passed. --- app/controllers/session_controller.rb | 2 +- lib/discourse.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/session_controller.rb b/app/controllers/session_controller.rb index 9c8216522ce..a11b1bc7a8f 100644 --- a/app/controllers/session_controller.rb +++ b/app/controllers/session_controller.rb @@ -594,7 +594,7 @@ class SessionController < ApplicationController client_ip: request&.ip, user_agent: request&.user_agent, } - DiscourseEvent.trigger(:before_session_destroy, event_data) + DiscourseEvent.trigger(:before_session_destroy, event_data, **Discourse::Utils::EMPTY_KEYWORDS) redirect_url = event_data[:redirect_url] reset_session diff --git a/lib/discourse.rb b/lib/discourse.rb index acb8d2060d5..577ae781008 100644 --- a/lib/discourse.rb +++ b/lib/discourse.rb @@ -12,6 +12,9 @@ module Discourse class Utils URI_REGEXP ||= URI.regexp(%w[http https]) + # TODO: Remove this once we drop support for Ruby 2. + EMPTY_KEYWORDS ||= {} + # Usage: # Discourse::Utils.execute_command("pwd", chdir: 'mydirectory') # or with a block