Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/face/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def template_for(face, action)

def erb(name)
template = (Pathname(__FILE__).dirname + "help" + name)
erb = ERB.new(template.read, nil, '-')
erb = Puppet::Util.create_erb(template.read)
erb.filename = template.to_s
return erb
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/generate/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def self.generate(inputs, outputdir = nil, force = false)
templates = {}
templates.default_proc = lambda { |hash, key|
raise _("template was not found at '%{key}'.") % { key: key } unless Puppet::FileSystem.file?(key)
template = ERB.new(File.read(key), nil, '-')
template = Puppet::Util.create_erb(File.read(key))
template.filename = key
template
}
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/templatewrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def result(string = nil)

result = nil
benchmark(:debug, _("Interpolated template %{template_source} in %%{seconds} seconds") % { template_source: escaped_template_source }) do
template = ERB.new(string, 0, "-")
template = Puppet::Util.create_erb(string)
template.filename = @__file__
result = template.result(binding)
end
Expand Down
11 changes: 11 additions & 0 deletions lib/puppet/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ def default_env
end
module_function :default_env

if RUBY_VERSION >= "2.6"
def create_erb(content)
ERB.new(content, trim_mode: '-')
end
else
def create_erb(content)
ERB.new(content, 0, '-')
end
end
module_function :create_erb

# @param name [String] The name of the environment variable to retrieve
# @param mode [Symbol] Which operating system mode to use e.g. :posix or :windows. Use nil to autodetect
# @return [String] Value of the specified environment variable. nil if it does not exist
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/resource_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Puppet::Util::ResourceTemplate

def evaluate
set_resource_variables
ERB.new(Puppet::FileSystem.read(@file, :encoding => 'utf-8'), 0, "-").result(binding)
Puppet::Util.create_erb(Puppet::FileSystem.read(@file, :encoding => 'utf-8')).result(binding)
end

def initialize(file, resource)
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/util/resource_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

it "should create a template instance with the contents of the file" do
expect(Puppet::FileSystem).to receive(:read).with("/my/template", :encoding => 'utf-8').and_return("yay")
expect(ERB).to receive(:new).with("yay", 0, "-").and_return(@template)
expect(Puppet::Util).to receive(:create_erb).with("yay").and_return(@template)

allow(@wrapper).to receive(:set_resource_variables)

Expand Down