Skip to content

Commit

Permalink
Merge pull request #9012 from AriaXLi/PUP-11754/Json.load_handles_emp…
Browse files Browse the repository at this point in the history
…ty_string

(PUP-11754) Empty metadata files should be treated as though they don't exist
  • Loading branch information
joshcooper authored Mar 10, 2023
2 parents 91a9528 + f2d0b4d commit f4781e3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/puppet/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ def license_file

def read_metadata
md_file = metadata_file
md_file.nil? ? {} : Puppet::Util::Json.load(File.read(md_file, :encoding => 'utf-8'))
return {} if md_file.nil?
content = File.read(md_file, :encoding => 'utf-8')
content.empty? ? {} : Puppet::Util::Json.load(content)
rescue Errno::ENOENT
{}
rescue Puppet::Util::Json::ParseError => e
Expand Down
2 changes: 0 additions & 2 deletions lib/puppet/module/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ def initialize(pup_module, task_name, module_executables, metadata_file = nil)
end

def self.read_metadata(file)
# MultiJSON has a bug that improperly errors when loading an empty string
# so we handle it here for now. See: PUP-11629
if file
content = Puppet::FileSystem.read(file, :encoding => 'utf-8')
content.empty? ? {} : Puppet::Util::Json.load(content)
Expand Down
1 change: 0 additions & 1 deletion spec/unit/pops/loaders/loaders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ def expect_loader_hierarchy(loaders, expected_loaders)
end

it 'loader allows loading a function more than once' do
pending('See PUP-11754')
allow(File).to receive(:read).with(user_metadata_path, {:encoding => 'utf-8'}).and_return('')
allow(File).to receive(:read).with(usee_metadata_path, {:encoding => 'utf-8'}).and_raise(Errno::ENOENT)
allow(File).to receive(:read).with(usee2_metadata_path, {:encoding => 'utf-8'}).and_raise(Errno::ENOENT)
Expand Down

0 comments on commit f4781e3

Please sign in to comment.