Skip to content

Commit f4781e3

Browse files
authored
Merge pull request #9012 from AriaXLi/PUP-11754/Json.load_handles_empty_string
(PUP-11754) Empty metadata files should be treated as though they don't exist
2 parents 91a9528 + f2d0b4d commit f4781e3

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

lib/puppet/module.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ def license_file
214214

215215
def read_metadata
216216
md_file = metadata_file
217-
md_file.nil? ? {} : Puppet::Util::Json.load(File.read(md_file, :encoding => 'utf-8'))
217+
return {} if md_file.nil?
218+
content = File.read(md_file, :encoding => 'utf-8')
219+
content.empty? ? {} : Puppet::Util::Json.load(content)
218220
rescue Errno::ENOENT
219221
{}
220222
rescue Puppet::Util::Json::ParseError => e

lib/puppet/module/task.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ def initialize(pup_module, task_name, module_executables, metadata_file = nil)
232232
end
233233

234234
def self.read_metadata(file)
235-
# MultiJSON has a bug that improperly errors when loading an empty string
236-
# so we handle it here for now. See: PUP-11629
237235
if file
238236
content = Puppet::FileSystem.read(file, :encoding => 'utf-8')
239237
content.empty? ? {} : Puppet::Util::Json.load(content)

spec/unit/pops/loaders/loaders_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ def expect_loader_hierarchy(loaders, expected_loaders)
246246
end
247247

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

0 commit comments

Comments
 (0)