diff --git a/app/models/repository/mercurial.rb b/app/models/repository/mercurial.rb index c38236fc8..102c6dda8 100644 --- a/app/models/repository/mercurial.rb +++ b/app/models/repository/mercurial.rb @@ -71,6 +71,7 @@ class Repository::Mercurial < Repository # Finds and returns a revision with a number or the beginning of a hash def find_changeset_by_name(name) + return nil if name.nil? || name.empty? if /[^\d]/ =~ name or name.to_s.size > 8 e = changesets.find(:first, :conditions => ['scmid = ?', name.to_s]) else diff --git a/test/functional/repositories_mercurial_controller_test.rb b/test/functional/repositories_mercurial_controller_test.rb index 1afe42571..b565863c3 100644 --- a/test/functional/repositories_mercurial_controller_test.rb +++ b/test/functional/repositories_mercurial_controller_test.rb @@ -195,6 +195,16 @@ class RepositoriesMercurialControllerTest < ActionController::TestCase :attributes => { :class => 'line-num' }, :sibling => { :tag => 'td', :content => /watcher =/ } end + + def test_empty_revision + @repository.fetch_changesets + @repository.reload + ['', ' ', nil].each do |r| + get :revision, :id => 1, :rev => r + assert_response 500 + assert_error_tag :content => /was not found/ + end + end else puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" def test_fake; assert true end diff --git a/test/unit/repository_mercurial_test.rb b/test/unit/repository_mercurial_test.rb index 8921acb76..7523cfe9d 100644 --- a/test/unit/repository_mercurial_test.rb +++ b/test/unit/repository_mercurial_test.rb @@ -154,6 +154,14 @@ class RepositoryMercurialTest < ActiveSupport::TestCase assert_equal '2:400bb8672109', c.format_identifier end + def test_find_changeset_by_empty_name + @repository.fetch_changesets + @repository.reload + ['', ' ', nil].each do |r| + assert_nil @repository.find_changeset_by_name(r) + end + end + def test_activities c = Changeset.new(:repository => @repository, :committed_on => Time.now,