Skip to content

Commit

Permalink
Escape { and } characters in filenames
Browse files Browse the repository at this point in the history
* Add test coverage for escaping { and } filename characters

Fixes #2087
  • Loading branch information
jordansissel committed Dec 19, 2024
1 parent 08dc21b commit 93ac157
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 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,8 @@ 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

0 comments on commit 93ac157

Please sign in to comment.