Skip to content

Commit

Permalink
Fixes #35145 - strip out + and ~ from package versions
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni authored and upadhyeammit committed Jun 30, 2022
1 parent 6abecd1 commit 09a35da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/foreman_maintain/concerns/system_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ def shellescape(string)
end

def version(value)
# packages versions, especially on Debian, sometimes include a + or a ~,
# but Gem::Version can't handle that.
value.gsub!(/[+~]/, '-')
Version.new(value)
end

Expand Down
22 changes: 22 additions & 0 deletions test/lib/concerns/system_helpers_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'test_helper'

class FakeSystem
include ForemanMaintain::Concerns::SystemHelpers
end

module ForemanMaintain
describe Concerns::SystemHelpers do
let(:system) { FakeSystem.new }

describe '.version' do
it 'can parse a normal version' do
assert system.version('1.2.3')
end

it 'can parse a weird nightly package version' do
assert system.version('9999-3.4.0-bullseye+scratchbuild+20220623140206')
assert system.version('1.4.7-1~tfm+1')
end
end
end
end

0 comments on commit 09a35da

Please sign in to comment.