From 5dcda19afa960de710c8a8dee8cb52ada075938c Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Mon, 25 Nov 2024 14:14:53 -0800 Subject: [PATCH 1/3] Add space to URI error The URI gem recently updated its error messages to include a space where there previously was not one: ruby/uri@9f2c7ed5f2e2c4060c05e3db8fa1dc73dd24ba0f This commit updates our test to reflect that change. (cherry picked from commit c3a5090d64c463f9a039d3648f1b53440be2c896) --- spec/unit/provider/package/puppetserver_gem_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/unit/provider/package/puppetserver_gem_spec.rb b/spec/unit/provider/package/puppetserver_gem_spec.rb index 170877b8a79..37b32cf1b31 100644 --- a/spec/unit/provider/package/puppetserver_gem_spec.rb +++ b/spec/unit/provider/package/puppetserver_gem_spec.rb @@ -77,7 +77,13 @@ it "raises if given an invalid URI" do resource[:source] = 'h;ttp://rubygems.com' - expect { provider.install }.to raise_error(Puppet::Error, /Invalid source '': bad URI\(is not URI\?\)/) + # Older versions of URI don't have a space before the opening + # parenthesis in the error message, newer versions do + if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('3.0.0') + expect { provider.install }.to raise_error(Puppet::Error, /Invalid source '': bad URI\(is not URI\?\)/) + else + expect { provider.install }.to raise_error(Puppet::Error, /Invalid source '': bad URI \(is not URI\?\)/) + end end end end From 562af0f43b4dec43f7fb093f531999bbe58aa409 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Mon, 25 Nov 2024 15:41:34 -0800 Subject: [PATCH 2/3] Maintain consistent JSON formatting The JSON gem has historically included newlines when pretty printing empty arrays or hashes. This changed with ruby/json@b2c4480 in JSON 2.8.0. In order to maintain consistent behavior for our users, this commit special cases empty array and hash facts and adds a new test for empty hashes. (cherry picked from commit 295d2f9071a46d82f73947963f761471bd011d88) --- lib/puppet/face/facts.rb | 10 +++++++++- spec/unit/application/facts_spec.rb | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/puppet/face/facts.rb b/lib/puppet/face/facts.rb index 1c16905ac48..20eda733b46 100644 --- a/lib/puppet/face/facts.rb +++ b/lib/puppet/face/facts.rb @@ -164,7 +164,15 @@ case result when Array, Hash - Puppet::Util::Json.dump(result, :pretty => true) + # JSON < 2.8.0 would pretty print empty arrays and hashes with newlines + # Maintain that behavior for our users for now + if result.is_a?(Array) && result.empty? + "[\n\n]" + elsif result.is_a?(Hash) && result.empty? + "{\n}" + else + Puppet::Util::Json.dump(result, :pretty => true) + end else # one of VALID_TYPES above result end diff --git a/spec/unit/application/facts_spec.rb b/spec/unit/application/facts_spec.rb index 24d08c59a20..c3aecd04257 100644 --- a/spec/unit/application/facts_spec.rb +++ b/spec/unit/application/facts_spec.rb @@ -91,6 +91,7 @@ { "type_hash" => [{'a' => 2}, "{\n \"a\": 2\n}"], + "type_empty_hash" => [{}, "{\n}"], "type_array" => [[], "[\n\n]"], "type_string" => ["str", "str"], "type_int" => [1, "1"], From f83f3fedf4cd33a545e8d599300295d37ff14c56 Mon Sep 17 00:00:00 2001 From: Michael Hashizume Date: Mon, 25 Nov 2024 16:05:58 -0800 Subject: [PATCH 3/3] Add Style/AccessModifierDeclarations exclusions Rubocop recently started flagging several files for violations of the Style/AccessModifierDeclarations cop. This only occurs in 7.x as many Rubocop fixes have landed in main/8.x. Because 7.x is so close to its end-of-life, these violations aren't really worth fixing and this commit excludes them from the cop. --- .rubocop_todo.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f4e262fb031..271b263b256 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -920,7 +920,10 @@ Naming/VariableNumber: # SupportedStyles: inline, group Style/AccessModifierDeclarations: Exclude: + - 'lib/puppet/util/command_line/trollop.rb' - 'lib/puppet/util/suidmanager.rb' + - 'lib/puppet/util/windows/com.rb' + - 'lib/puppet/util/windows/monkey_patches/process.rb' # This cop supports safe auto-correction (--auto-correct). # Configuration parameters: EnforcedStyle.