File tree 6 files changed +40
-77
lines changed
6 files changed +40
-77
lines changed Original file line number Diff line number Diff line change 16
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
18
18
require 'puppet_library/util/patches'
19
- require 'puppet_library/util/version'
20
19
21
20
module PuppetLibrary ::Forge
22
21
module SearchResult
@@ -47,7 +46,7 @@ def self.combine_search_results(search_results)
47
46
end
48
47
49
48
def self . max_version ( left , right )
50
- [ PuppetLibrary :: Util :: Version . new ( left ) , PuppetLibrary :: Util ::Version . new ( right ) ] . max . version
49
+ [ Gem :: Version . new ( left ) , Gem ::Version . new ( right ) ] . max . version
51
50
end
52
51
end
53
52
end
Original file line number Diff line number Diff line change @@ -23,4 +23,3 @@ module PuppetLibrary::Util
23
23
require 'puppet_library/util/logging'
24
24
require 'puppet_library/util/patches'
25
25
require 'puppet_library/util/temp_dir'
26
- require 'puppet_library/util/version'
Original file line number Diff line number Diff line change 16
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
18
18
require 'rubygems/package'
19
- require 'puppet_library/util/version'
19
+
20
+ # Early versions of Rubygems have problems with version numbers with dashes
21
+ # (e.g. "1.0.0-rc1"). This adds the behaviour or new RG versions to all
22
+ # versions, hopefully without breaking newer versions. In most cases we want to
23
+ # fail silently with bad version numbers so that we don't crash the server
24
+ # because of weird stuff from a remote forge or elsewhere.
25
+ module Gem
26
+ def Version . new ( version )
27
+ super ( version . to_s . gsub ( "-" , ".pre." ) )
28
+ rescue ArgumentError
29
+ # If it starts with numbers, use those
30
+ if version =~ /^\d +(\. \d +)*/
31
+ super ( version [ /^\d +(\. \d +)*/ ] )
32
+ # Somebody's really made a mess of this version number
33
+ else
34
+ super ( "0" )
35
+ end
36
+ end
37
+ end
20
38
21
39
class Array
22
40
# Like 'uniq' with a block, but also works on Ruby < 1.9
@@ -39,7 +57,7 @@ def version_sort
39
57
def version_sort_by
40
58
sort_by do |element |
41
59
version = yield ( element )
42
- PuppetLibrary :: Util ::Version . new ( version )
60
+ Gem ::Version . new ( version )
43
61
end
44
62
end
45
63
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 18
18
require 'spec_helper'
19
19
20
20
describe 'patches' do
21
+ describe Gem ::Version do
22
+ describe "#new" do
23
+ context "when the version number contains a dash" do
24
+ it "replaces the dash with '.pre.'" do
25
+ expect ( Gem ::Version . new ( "1.0.0-rc1" ) ) . to eq Gem ::Version . new ( "1.0.0.pre.rc1" )
26
+ end
27
+ end
28
+ context "when the version number has trailing garbage" do
29
+ it "uses the numbers at the beginning" do
30
+ expect ( Gem ::Version . new ( "123 xyz" ) ) . to eq Gem ::Version . new ( "123" )
31
+ end
32
+ end
33
+ context "when the version is completely garbage" do
34
+ it "pretends the version number is zero" do
35
+ expect ( Gem ::Version . new ( "xyz" ) ) . to eq Gem ::Version . new ( "0" )
36
+ end
37
+ end
38
+ end
39
+ end
21
40
22
41
describe Array do
23
42
describe "#unique_by" do
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments