From 5cf05f4d5d084d371302625ac2128bf034fdec86 Mon Sep 17 00:00:00 2001 From: Oleh Fedorenko Date: Fri, 7 Nov 2025 12:43:30 +0000 Subject: [PATCH] Fixes #38894 - Update logger for #inspect of Ruby 3.1+ --- lib/hammer_cli/logger.rb | 2 +- test/unit/abstract_test.rb | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/hammer_cli/logger.rb b/lib/hammer_cli/logger.rb index ee3d93895..31db7b9a5 100644 --- a/lib/hammer_cli/logger.rb +++ b/lib/hammer_cli/logger.rb @@ -28,7 +28,7 @@ def self.data_filters end # add password filter: *password => "***" -Logging::LogEvent.add_data_filter(/(password(\e\[0;\d{2}m|\e\[0m|\s|=>|")+\")[^\"]*\"/, '\1***"') +Logging::LogEvent.add_data_filter(/(password(\e\[0;\d{2}m|\e\[0m|\s|=>|:|")+\")[^\"]*\"/, '\1***"') module HammerCLI module Logger diff --git a/test/unit/abstract_test.rb b/test/unit/abstract_test.rb index bc45afe88..42a6f25b6 100644 --- a/test/unit/abstract_test.rb +++ b/test/unit/abstract_test.rb @@ -147,7 +147,11 @@ def execute it "should have logger.watch output without colors" do test_command = Class.new(TestLogCmd4).new("") test_command.run [] - _(@log_output.read).must_include "DEBUG TestLogCmd4 : Test\n{\n :a => \"a\"\n}" + if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1') # TODO: remove when Ruby 3.0 is not supported + _(@log_output.read).must_include "DEBUG TestLogCmd4 : Test\n{\n :a => \"a\"\n}" + else + _(@log_output.read).must_include "DEBUG TestLogCmd4 : Test\n{\n a: \"a\"\n}" + end end class TestLogCmd5 < HammerCLI::AbstractCommand @@ -162,7 +166,11 @@ def execute HammerCLI::Settings.clear HammerCLI::Settings.load(:watch_plain => true) test_command.run [] - _(@log_output.read).must_include "DEBUG TestLogCmd5 : Test\n{\n :a => \"a\"\n}" + if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1') # TODO: remove when Ruby 3.0 is not supported + _(@log_output.read).must_include "DEBUG TestLogCmd5 : Test\n{\n :a => \"a\"\n}" + else + _(@log_output.read).must_include "DEBUG TestLogCmd5 : Test\n{\n a: \"a\"\n}" + end end class TestLogCmd6 < HammerCLI::AbstractCommand @@ -177,7 +185,11 @@ def execute HammerCLI::Settings.clear HammerCLI::Settings.load(:watch_plain => true) test_command.run [] - _(@log_output.read).must_include "DEBUG TestLogCmd6 : Test\n{\n :password => \"***\",\n \"password\" => \"***\"\n}" + if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.1') # TODO: remove when Ruby 3.0 is not supported + _(@log_output.read).must_include "DEBUG TestLogCmd6 : Test\n{\n :password => \"***\",\n \"password\" => \"***\"\n}" + else + _(@log_output.read).must_include "DEBUG TestLogCmd6 : Test\n{\n password: \"***\",\n \"password\" => \"***\"\n}" + end end it "password parameters should be hidden in logs" do