Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpm: Escape { and } characters in filenames #2088

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions lib/fpm/package/rpm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ class FPM::Package::RPM < FPM::Package
# If and only if any of the above are done, then also replace ' with \', " with \", and \ with \\\\
# to accommodate escape and quote processing that rpm will perform in that case (but not otherwise)
def rpm_fix_name(name)
if name.match?(/[ \t*?%$\[\]]/)
name = name.gsub(/(\ |\t|\[|\]|\*|\?|\%|\$|'|"|\\)/, {
if name.match?(/[ \t*?%${}\[\]]/)
name = name.gsub(/(\ |\t|\[|\]|\*|\?|\%|\$|'|"|\{|\}|\\)/, {
' ' => '?',
"\t" => '?',
'%' => '[%]',
Expand All @@ -209,6 +209,10 @@ def rpm_fix_name(name)
'*' => '[*]',
'[' => '[\[]',
']' => '[\]]',
#'{' => '[\{]',
#'}' => '[\}]',
'{' => '?',
'}' => '?',
'"' => '\\"',
"'" => "\\'",
'\\' => '\\\\\\\\',
Expand Down
9 changes: 9 additions & 0 deletions spec/fpm/package/rpm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,15 @@ def subject.render_template; @rpmspec = template("rpm.erb").result(binding); end
insist { rpm.files } == [ "/example/%name%" ]
end

it "should escape '{' and '}' characters in filenames" do
Dir.mkdir(subject.staging_path("/example"))
File.write(subject.staging_path("/example/{{ test }}"), "Hello")
subject.output(@target)

rpm = ::RPM::File.new(@target)
insist { rpm.files } == [ "/example/{{ test }}" ]
end

it "should correctly include files with spaces and quotation marks" do
names = [
"/It's time to go.txt",
Expand Down
9 changes: 5 additions & 4 deletions spec/spec_setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
require "fpm/util"
include FPM::Util

Cabin::Channel.get.level = :error
spec_logger = Cabin::Channel.get("rspec")
spec_logger.subscribe(STDOUT)
spec_logger.level = :error

# Enable debug logs if requested.
if $DEBUG or ENV["DEBUG"]
Cabin::Channel.get.level = :debug
Expand All @@ -28,10 +33,6 @@ def subscribe(io)
end
end

Cabin::Channel.get.level = :error
spec_logger = Cabin::Channel.get("rspec")
spec_logger.subscribe(STDOUT)
spec_logger.level = :error

# Quiet the output of all system() calls
module Kernel
Expand Down