Skip to content

Commit b1e80b4

Browse files
authored
Merge pull request #1101 from tkishel/MODULES-10623_scope_json
(MODULES-10623) explicitly top-scope calls to JSON methods
2 parents f560fee + da96c7c commit b1e80b4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/facter/facter_dot_d.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ def json_parser(file)
6666
retry if require 'rubygems'
6767
raise
6868
end
69-
70-
JSON.parse(File.read(file)).each_pair do |f, v|
69+
# Call ::JSON to ensure it references the JSON library from Ruby’s standard library
70+
# instead of a random JSON namespace that might be in scope due to user code.
71+
::JSON.parse(File.read(file)).each_pair do |f, v|
7172
Facter.add(f) do
7273
setcode { v }
7374
end

lib/puppet/functions/to_json_pretty.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'json'
2+
23
# @summary
34
# Convert data structure and output to pretty JSON
45
#
@@ -72,6 +73,8 @@ def to_json_pretty(data, skip_undef = false, opts = nil)
7273
data = data.reject { |_, value| value.nil? }
7374
end
7475
end
75-
JSON.pretty_generate(data, opts) << "\n"
76+
# Call ::JSON to ensure it references the JSON library from Ruby’s standard library
77+
# instead of a random JSON namespace that might be in scope due to user code.
78+
::JSON.pretty_generate(data, opts) << "\n"
7679
end
7780
end

0 commit comments

Comments
 (0)